import numpy as np



H, W = list(map(int, input().split()))

lst1 = []

lst2 = []

for _ in range(H):

    lst1.append([int(i) for i in input().split()])

for _ in range(H):

    lst2.append([int(i) for i in input().split()])

arr1, arr2 = np.array(lst1), np.array(lst2)

arr = np.abs(arr1 - arr2)



d = [[0] * W for _ in range(H)]

m = 80 * (H + W)

d[0][0] = 1 << m

for h in range(H):

    for w in range(W):

        x = arr[h][w]

        if h > 0:

            d[h][w] |= d[h - 1][w]

        if w > 0:

            d[h][w] |= d[h][w - 1]

        d[h][w] = d[h][w] << x | d[h][w] >> x



x, y= 1 << m, 1 << m

for i in range(m + 1):

    if d[H - 1][W - 1] & x or d[H - 1][W - 1] & y:

        print(i)

        quit()

    x<<=1

    y>>=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)]

d=[[0]*W for j in range(H)]

m=80*(H+W)

d[0][0]=1<<m

for h in range(H):

    for w in range(W):

        x=abs(A[h][w]-B[h][w])

        if h>0:

            d[h][w]|=d[h-1][w]

        if w>0:

            d[h][w]|=d[h][w-1]

        d[h][w]=d[h][w]<<x|d[h][w]>>x

x,y=1<<m,1<<m

for i in range(99):

    if d[H-1][W-1]&x or d[H-1][W-1]&y:

        print(i)

        exit()

    x<<=1

    y>>=1

import numpy as np

H, W = list(map(int, input().split()))
lst1 = []
lst2 = []
for _ in range(H):
    lst1.append([int(i) for i in input().split()])
for _ in range(H):
    lst2.append([int(i) for i in input().split()])
arr1, arr2 = np.array(lst1), np.array(lst2)
arr = np.abs(arr1 - arr2)
d = [[0] * W for _ in range(H)]
m = 80 * (H + W)
d[0][0] = 1 << m
for h in range(H):
    for w in range(W):
        x = arr[h][w]
        if h > 0:
            d[h][w] |= d[h - 1][w]
        if w > 0:
            d[h][w] |= d[h][w - 1]
        d[h][w] = d[h][w] << x | d[h][w] >> x
x, y = 1 << m, 1 << m
for i in range(m + 1):
    if d[H - 1][W - 1] & x or d[H - 1][W - 1] & y:
        print(i)
        quit()
    x <<= 1
    y >>= 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)]
d = [[0] * W for j in range(H)]
m = 80 * (H + W)
d[0][0] = 1 << m
for h in range(H):
    for w in range(W):
        x = abs(A[h][w] - B[h][w])
        if h > 0:
            d[h][w] |= d[h - 1][w]
        if w > 0:
            d[h][w] |= d[h][w - 1]
        d[h][w] = d[h][w] << x | d[h][w] >> x
x, y = 1 << m, 1 << m
for i in range(99):
    if d[H - 1][W - 1] & x or d[H - 1][W - 1] & y:
        print(i)
        exit()
    x <<= 1
    y >>= 1

-import numpy as np - -lst1 = [] -lst2 = [] -for _ in range(H): -    lst1.append([int(i) for i in input().split()]) -for _ in range(H): -    lst2.append([int(i) for i in input().split()]) -arr1, arr2 = np.array(lst1), np.array(lst2) -arr = np.abs(arr1 - arr2) -d = [[0] * W for _ in range(H)] +A = [list(map(int, input().split())) for i in range(H)] +B = [list(map(int, input().split())) for i in range(H)] +d = [[0] * W for j in range(H)] -        x = arr[h][w] +        x = abs(A[h][w] - B[h][w]) -for i in range(m + 1): +for i in range(99): -        quit() +        exit()