# Original solution
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
from collections import Counter
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

import sys
import itertools
# import numpy as np
import time
import math
from heapq import heappop, heappush
from collections import defaultdict
from collections import Counter
from collections import deque
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())
H, W = list(map(int, input().split()))
A = [0] * H
for i in range(H):
    A[i] = list(map(int, input().split()))
B = [0] * H
for i in range(H):
    B[i] = list(map(int, input().split()))

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

MAX = H * W
dp = [[[INF] * W for _ in range(H)] for _ in range(MAX)]
for k in range(MAX):
    for i in range(H):
        for j in range(W):
            if k == 0:
                if i == 0 and j == 0:
                    dp[k][i][j] = C[i][j]
                elif i == 0:
                    dp[k][i][j] = dp[k][i][j - 1] + C[i][j]
                elif j == 0:
                    dp[k][i][j] = dp[k][i - 1][j] + C[i][j]
                else:
                    dp[k][i][j] = min(dp[k][i - 1][j], dp[k][i][j - 1]) + C[i][j]
            else:
                if i == 0 and j == 0:
                    continue
                elif i == 0:
                    dp[k][i][j] = min(abs(dp[k - 1][i][j - 1] - C[i][j]), dp[k][i][j])
                elif j == 0:
                    dp[k][i][j] = min(abs(dp[k - 1][i - 1][j] - C[i][j]), dp[k][i][j])
                else:
                    dp[k][i][j] = min(abs(dp[k - 1][i - 1][j] - C[i][j]), \
                        abs(dp[k - 1][i][j - 1] - C[i][j]), dp[k][i][j])

ans = INF
for k in range(MAX):
    val = dp[k][H - 1][W - 1]
    ans = min(ans, val)
print(ans)

# Optimized solution
import sys
import itertools
# import numpy as np
import time
import math
from heapq import heappop, heappush
from collections import defaultdict
from collections import Counter
from collections import deque
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())
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)]
C = [[abs(A[i][j] - B[i][j]) for j in range(W)] for i in range(H)]
 
X = (H + W) * 80
L = X + X + 1
dp = [[0] * W for _ in range(H)]

# X点持った状態から始める
dp[0][0] |= 1 << (X - C[0][0])
dp[0][0] |= 1 << (X + C[0][0])
for i in range(H):
    for j in range(W):
        if i > 0:
            dp[i][j] |= dp[i - 1][j] << C[i][j]
            dp[i][j] |= dp[i - 1][j] >> C[i][j]
        if j > 0:
            dp[i][j] |= dp[i][j - 1] << C[i][j]
            dp[i][j] |= dp[i][j - 1] >> C[i][j]

ans = L
for i in range(L):
    if dp[-1][-1] & 1 << i > 0:
        ans = min(ans, abs(i - X))
print(ans)