def x():

	return list(map(int,input().split()))

v=list

c=abs

r=range

h,w=x()

p=v(r(h))

a=[v(x())for i in p]

b=[v(x())for i in p]

m=13120

D=[[[0]*m for i in r(w)]for i in p]

for i in p:

	for j in r(w):

		k=c(a[i][j]-b[i][j])

		if i|j:

			for l in r((i+j+1)*80+1):

				e=c(l-k)

				D[i][j][l]=D[i][j-1][e]|D[i][j-1][l+k]|D[i-1][j][e]|D[i-1][j][l+k]

		else:

			D[i][j][k]=1

print((D[-1][-1].index(1)))
h,w = list(map(int, input().split()))

a = [list(map(int, input().split())) for i in range(h)]

b = [list(map(int, input().split())) for i in range(h)]

# zeroは真ん中にする

ma = 80*2*80

DP = [[0]*w for i in range(h)]



for i in range(h):

    for j in range(w):

        k = abs(a[i][j]-b[i][j])

        if i|j:

            m = DP[i-1][j]|DP[i][j-1]

        else:

            m = 1<<ma

        DP[i][j] = (m<<k)|(m>>k)



k = 1<<ma

for i in range(ma):

    if DP[-1][-1]&(k>>i) or DP[-1][-1]&(k<<i):

        print(i)

        exit()
def x():
    return list(map(int, input().split()))


v = list
c = abs
r = range
h, w = x()
p = v(r(h))
a = [v(x()) for i in p]
b = [v(x()) for i in p]
m = 13120
D = [[[0] * m for i in r(w)] for i in p]
for i in p:
    for j in r(w):
        k = c(a[i][j] - b[i][j])
        if i | j:
            for l in r((i + j + 1) * 80 + 1):
                e = c(l - k)
                D[i][j][l] = (
                    D[i][j - 1][e]
                    | D[i][j - 1][l + k]
                    | D[i - 1][j][e]
                    | D[i - 1][j][l + k]
                )
        else:
            D[i][j][k] = 1
print((D[-1][-1].index(1)))

h, w = list(map(int, input().split()))
a = [list(map(int, input().split())) for i in range(h)]
b = [list(map(int, input().split())) for i in range(h)]
# zeroは真ん中にする
ma = 80 * 2 * 80
DP = [[0] * w for i in range(h)]
for i in range(h):
    for j in range(w):
        k = abs(a[i][j] - b[i][j])
        if i | j:
            m = DP[i - 1][j] | DP[i][j - 1]
        else:
            m = 1 << ma
        DP[i][j] = (m << k) | (m >> k)
k = 1 << ma
for i in range(ma):
    if DP[-1][-1] & (k >> i) or DP[-1][-1] & (k << i):
        print(i)
        exit()

-def x(): -    return list(map(int, input().split())) - - -v = list -c = abs -r = range -h, w = x() -p = v(r(h)) -a = [v(x()) for i in p] -b = [v(x()) for i in p] -m = 13120 -D = [[[0] * m for i in r(w)] for i in p] -for i in p: -    for j in r(w): -        k = c(a[i][j] - b[i][j]) +h, w = list(map(int, input().split())) +a = [list(map(int, input().split())) for i in range(h)] +b = [list(map(int, input().split())) for i in range(h)] +# zeroは真ん中にする +ma = 80 * 2 * 80 +DP = [[0] * w for i in range(h)] +for i in range(h): +    for j in range(w): +        k = abs(a[i][j] - b[i][j]) -            for l in r((i + j + 1) * 80 + 1): -                e = c(l - k) -                D[i][j][l] = ( -                    D[i][j - 1][e] -                    | D[i][j - 1][l + k] -                    | D[i - 1][j][e] -                    | D[i - 1][j][l + k] -                ) +            m = DP[i - 1][j] | DP[i][j - 1] -            D[i][j][k] = 1 -print((D[-1][-1].index(1))) +            m = 1 << ma +        DP[i][j] = (m << k) | (m >> k) +k = 1 << ma +for i in range(ma): +    if DP[-1][-1] & (k >> i) or DP[-1][-1] & (k << i): +        print(i) +        exit()