def main():

    import sys

    input = sys.stdin.readline

    sys.setrecursionlimit(10**7)

    from collections import Counter, deque

    from itertools import combinations, permutations, accumulate, groupby, product

    from bisect import bisect_left,bisect_right

    from heapq import heapify, heappop, heappush

    import math

    #from math import gcd



    #inf = 10**17

    #mod = 10**9 + 7



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

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

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

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

    for i in range(h):

        for j in range(w):

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



    mid = 12800

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

    dp[0][0] = (1<<(mid+c[0][0])) | (1<<(mid-c[0][0]))

    for x in range(h):

        for y in range(w):

            for dx, dy in [[0, 1], [1, 0]]:

                nx = x + dx

                ny = y + dy

                if 0<=nx<h and 0<=ny<w:

                    dp[nx][ny] = dp[nx][ny] | (dp[x][y]<<c[nx][ny])

                    dp[nx][ny] = dp[nx][ny] | (dp[x][y]>>c[nx][ny])

    

    for i in range(mid+1):

        if (dp[-1][-1]>>i) & 1:

            res = mid - i



    print(res)



if __name__ == '__main__':

    main()
def main():

    import sys

    input = sys.stdin.readline

    sys.setrecursionlimit(10**7)

    from collections import Counter, deque

    from itertools import combinations, permutations, accumulate, groupby, product

    from bisect import bisect_left,bisect_right

    from heapq import heapify, heappop, heappush

    import math

    #from math import gcd



    #inf = 10**17

    #mod = 10**9 + 7



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

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

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

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

    for i in range(h):

        for j in range(w):

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



    mid = 3200

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

    dp[0][0] = (1<<(mid+c[0][0])) | (1<<(mid-c[0][0]))

    for x in range(h):

        for y in range(w):

            for dx, dy in [[0, 1], [1, 0]]:

                nx = x + dx

                ny = y + dy

                if 0<=nx<h and 0<=ny<w:

                    dp[nx][ny] = dp[nx][ny] | (dp[x][y]<<c[nx][ny])

                    dp[nx][ny] = dp[nx][ny] | (dp[x][y]>>c[nx][ny])

    

    for i in range(mid+1):

        if (dp[-1][-1]>>i) & 1:

            res = mid - i



    print(res)



if __name__ == '__main__':

    main()
def main():
    import sys

    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left, bisect_right
    from heapq import heapify, heappop, heappush
    import math

    # from math import gcd
    # inf = 10**17
    # mod = 10**9 + 7
    h, w = list(map(int, input().split()))
    a = [list(map(int, input().split())) for _ in range(h)]
    b = [list(map(int, input().split())) for _ in range(h)]
    c = [[0] * w for _ in range(h)]
    for i in range(h):
        for j in range(w):
            c[i][j] = abs(a[i][j] - b[i][j])
    mid = 12800
    dp = [[0] * w for _ in range(h)]
    dp[0][0] = (1 << (mid + c[0][0])) | (1 << (mid - c[0][0]))
    for x in range(h):
        for y in range(w):
            for dx, dy in [[0, 1], [1, 0]]:
                nx = x + dx
                ny = y + dy
                if 0 <= nx < h and 0 <= ny < w:
                    dp[nx][ny] = dp[nx][ny] | (dp[x][y] << c[nx][ny])
                    dp[nx][ny] = dp[nx][ny] | (dp[x][y] >> c[nx][ny])
    for i in range(mid + 1):
        if (dp[-1][-1] >> i) & 1:
            res = mid - i
    print(res)


if __name__ == "__main__":
    main()

def main():
    import sys

    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left, bisect_right
    from heapq import heapify, heappop, heappush
    import math

    # from math import gcd
    # inf = 10**17
    # mod = 10**9 + 7
    h, w = list(map(int, input().split()))
    a = [list(map(int, input().split())) for _ in range(h)]
    b = [list(map(int, input().split())) for _ in range(h)]
    c = [[0] * w for _ in range(h)]
    for i in range(h):
        for j in range(w):
            c[i][j] = abs(a[i][j] - b[i][j])
    mid = 3200
    dp = [[0] * w for _ in range(h)]
    dp[0][0] = (1 << (mid + c[0][0])) | (1 << (mid - c[0][0]))
    for x in range(h):
        for y in range(w):
            for dx, dy in [[0, 1], [1, 0]]:
                nx = x + dx
                ny = y + dy
                if 0 <= nx < h and 0 <= ny < w:
                    dp[nx][ny] = dp[nx][ny] | (dp[x][y] << c[nx][ny])
                    dp[nx][ny] = dp[nx][ny] | (dp[x][y] >> c[nx][ny])
    for i in range(mid + 1):
        if (dp[-1][-1] >> i) & 1:
            res = mid - i
    print(res)


if __name__ == "__main__":
    main()

-    mid = 12800 +    mid = 3200