package main

import (
	"bufio"
	"fmt"
	"math/big"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}
func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0
	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 1
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}
	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	h := getNextInt(scanner)
	w := getNextInt(scanner)
	aa := makeGrid(h, w)
	for i := 0; i < h; i++ {
		for j := 0; j < w; j++ {
			aa[i][j] = getNextInt(scanner)
		}
	}
	for i := 0; i < h; i++ {
		for j := 0; j < w; j++ {
			aa[i][j] -= getNextInt(scanner)
			if aa[i][j] < 0 {
				aa[i][j] = -aa[i][j]
			}
		}
	}
	dp := make([][]*bint, h)
	for i := 0; i < h; i++ {
		dp[i] = make([]*bint, w)
		for j := 0; j < w; j++ {
			dp[i][j] = newBint(0)
		}
	}
	geta := 10000
	dp[0][0].x.SetBit(dp[0][0].x, geta+aa[0][0], 1)
	dp[0][0].x.SetBit(dp[0][0].x, geta-aa[0][0], 1)
	for i := 1; i < w; i++ {
		dp[0][i] = dp[0][i].or(dp[0][i-1].lsh(aa[0][i]))
		dp[0][i] = dp[0][i].or(dp[0][i-1].rsh(aa[0][i]))
	}
	for i := 1; i < h; i++ {
		dp[i][0] = dp[i][0].or(dp[i-1][0].lsh(aa[i][0]))
		dp[i][0] = dp[i][0].or(dp[i-1][0].rsh(aa[i][0]))
	}
	for i := 1; i < h; i++ {
		for j := 1; j < w; j++ {
			dp[i][j] = dp[i][j].or(dp[i-1][j].lsh(aa[i][j]))
			dp[i][j] = dp[i][j].or(dp[i-1][j].rsh(aa[i][j]))
			dp[i][j] = dp[i][j].or(dp[i][j-1].lsh(aa[i][j]))
			dp[i][j] = dp[i][j].or(dp[i][j-1].rsh(aa[i][j]))
		}
	}
	for i := 0; i < geta; i++ {
		if dp[h-1][w-1].x.Bit(geta+i) == 1 {
			fmt.Fprintln(writer, i)
			return
		}
		if dp[h-1][w-1].x.Bit(geta-i) == 1 {
			fmt.Fprintln(writer, i)
			return
		}
	}
}
func makeGrid(h, w int) [][]int {
	index := make([][]int, h, h)
	data := make([]int, h*w, h*w)
	for i := 0; i < h; i++ {
		index[i] = data[i*w : (i+1)*w]
	}
	return index
}

type bint struct {
	x *big.Int
}

func newBint(x int64) *bint {
	return &bint{x: big.NewInt(x)}
}
func (x *bint) add(y *bint) *bint {
	z := newBint(0)
	z.x.Add(x.x, y.x)
	return z
}
func (x *bint) sub(y *bint) *bint {
	z := newBint(0)
	z.x.Sub(x.x, y.x)
	return z
}
func (x *bint) mul(y *bint) *bint {
	z := newBint(0)
	z.x.Mul(x.x, y.x)
	return z
}
func (x *bint) div(y *bint) *bint {
	z := newBint(0)
	z.x.Div(x.x, y.x)
	return z
}
func (x *bint) lsh(n int) *bint {
	z := newBint(0)
	z.x.Lsh(x.x, uint(n))
	return z
}
func (x *bint) rsh(n int) *bint {
	z := newBint(0)
	z.x.Rsh(x.x, uint(n))
	return z
}
func (x *bint) or(y *bint) *bint {
	z := newBint(0)
	z.x.Or(x.x, y.x)
	return z
}


Measured memory_bytes: 32256