H, W = [int(x) for x in input().split()]



A = [[0]*W for i in range(H)]

for c in [1, -1]:

    for i in range(H):

        arr = [int(x) for x in input().split()]

        for j in range(W):

            A[i][j] += arr[j] * c



M = 160*80

dp = [[0]*W for i in range(H)]

dp[0][0] = 1 << M

for i in range(H):

    for j in range(W):

        if i > 0:

            dp[i][j] |= dp[i-1][j]

        if j > 0:

            dp[i][j] |= dp[i][j-1]

        a = abs(A[i][j])

        dp[i][j] = (dp[i][j] << a) | (dp[i][j] >> a)



ans = M

for i in range(2*M):

    if dp[H-1][W-1] & (1 << i) > 0:

        ans = min(ans, abs(M-i))

print(ans)

# -*- coding: utf-8 -*-

import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines

# template





def resolve():

    ofs = 6400

    h, w = list(map(int, readline().split()))

    A = [list(map(int, readline().split())) for _ in range(h)]

    B = [list(map(int, readline().split())) for _ in range(h)]

    dp = [[0]*w for _ in range(h)]

    x = abs(A[0][0]-B[0][0])

    dp[0][0] |= ((1 << (ofs+x)) | (1 << (ofs-x)))



    from itertools import product

    for i, j in product(list(range(h)), list(range(w))):

        x = abs(A[i][j]-B[i][j])

        t = 0

        if(i-1 >= 0):

            t |= dp[i-1][j]

        if(j-1 >= 0):

            t |= dp[i][j-1]

        dp[i][j] |= ((t << x) | (t >> x))



    for i, s in enumerate(bin(dp[-1][-1])[-ofs-1:]):

        if(s == '1'):

            print(i)

            return





if __name__ == "__main__":

    INF = float("inf")

    MOD = 10**9+7

    resolve()

H, W = [int(x) for x in input().split()]
A = [[0] * W for i in range(H)]
for c in [1, -1]:
    for i in range(H):
        arr = [int(x) for x in input().split()]
        for j in range(W):
            A[i][j] += arr[j] * c
M = 160 * 80
dp = [[0] * W for i in range(H)]
dp[0][0] = 1 << M
for i in range(H):
    for j in range(W):
        if i > 0:
            dp[i][j] |= dp[i - 1][j]
        if j > 0:
            dp[i][j] |= dp[i][j - 1]
        a = abs(A[i][j])
        dp[i][j] = (dp[i][j] << a) | (dp[i][j] >> a)
ans = M
for i in range(2 * M):
    if dp[H - 1][W - 1] & (1 << i) > 0:
        ans = min(ans, abs(M - i))
print(ans)

# -*- coding: utf-8 -*-
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
# template
def resolve():
    ofs = 6400
    h, w = list(map(int, readline().split()))
    A = [list(map(int, readline().split())) for _ in range(h)]
    B = [list(map(int, readline().split())) for _ in range(h)]
    dp = [[0] * w for _ in range(h)]
    x = abs(A[0][0] - B[0][0])
    dp[0][0] |= (1 << (ofs + x)) | (1 << (ofs - x))
    from itertools import product

    for i, j in product(list(range(h)), list(range(w))):
        x = abs(A[i][j] - B[i][j])
        t = 0
        if i - 1 >= 0:
            t |= dp[i - 1][j]
        if j - 1 >= 0:
            t |= dp[i][j - 1]
        dp[i][j] |= (t << x) | (t >> x)
    for i, s in enumerate(bin(dp[-1][-1])[-ofs - 1 :]):
        if s == "1":
            print(i)
            return


if __name__ == "__main__":
    INF = float("inf")
    MOD = 10**9 + 7
    resolve()

-H, W = [int(x) for x in input().split()] -A = [[0] * W for i in range(H)] -for c in [1, -1]: -    for i in range(H): -        arr = [int(x) for x in input().split()] -        for j in range(W): -            A[i][j] += arr[j] * c -M = 160 * 80 -dp = [[0] * W for i in range(H)] -dp[0][0] = 1 << M -for i in range(H): -    for j in range(W): -        if i > 0: -            dp[i][j] |= dp[i - 1][j] -        if j > 0: -            dp[i][j] |= dp[i][j - 1] -        a = abs(A[i][j]) -        dp[i][j] = (dp[i][j] << a) | (dp[i][j] >> a) -ans = M -for i in range(2 * M): -    if dp[H - 1][W - 1] & (1 << i) > 0: -        ans = min(ans, abs(M - i)) -print(ans) +# -*- coding: utf-8 -*- +import sys + +read = sys.stdin.buffer.read +readline = sys.stdin.buffer.readline +readlines = sys.stdin.buffer.readlines +# template +def resolve(): +    ofs = 6400 +    h, w = list(map(int, readline().split())) +    A = [list(map(int, readline().split())) for _ in range(h)] +    B = [list(map(int, readline().split())) for _ in range(h)] +    dp = [[0] * w for _ in range(h)] +    x = abs(A[0][0] - B[0][0]) +    dp[0][0] |= (1 << (ofs + x)) | (1 << (ofs - x)) +    from itertools import product + +    for i, j in product(list(range(h)), list(range(w))): +        x = abs(A[i][j] - B[i][j]) +        t = 0 +        if i - 1 >= 0: +            t |= dp[i - 1][j] +        if j - 1 >= 0: +            t |= dp[i][j - 1] +        dp[i][j] |= (t << x) | (t >> x) +    for i, s in enumerate(bin(dp[-1][-1])[-ofs - 1 :]): +        if s == "1": +            print(i) +            return + + +if __name__ == "__main__": +    INF = float("inf") +    MOD = 10**9 + 7 +    resolve()