Buggy python submission (verdict: Time Limit Exceeded):
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq

h,w = ma()
A = []
for i in range(h):
    A.append(lma())
B= []
for i in range(h):
    B.append(lma())
D = [[abs(A[i][j]-B[i][j]) for j in range(w)] for i in range(h)]
mx = 0
for i in range(h):
    for j in range(w):
        mx = max(mx,D[i][j])
prev = [[False]*((h+w)*mx+1) for j in range(w)]
nex = [[False]*((h+w)*mx+1) for j in range(w)]
prev[0][0]=True
for i in range(h):
    for j in range(w):
        d = D[i][j]
        if j==0:
            for k in range((h+w)*mx+1-d):
                nex[j][k+d] = nex[j][k+d] or prev[j][k]
                nex[j][abs(k-d)] = nex[j][abs(k-d)] or prev[j][k]
        else:
            for k in range((h+w)*mx+1-d):
                nex[j][k+d] = nex[j][k+d] or prev[j][k] or nex[j-1][k]
                nex[j][abs(k-d)] = nex[j][abs(k-d)] or prev[j][k] or nex[j-1][k]
    prev=nex
    nex=[[False]*((h+w)*mx+1) for j in range(w)]
for i in range((h+w)*mx+1):
    if prev[w-1][i]:
        print(i)
        exit()


Fixed submission:
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq

h,w = ma()
A = []
for i in range(h):
    A.append(lma())
B= []
for i in range(h):
    B.append(lma())
D = [[abs(A[i][j]-B[i][j]) for j in range(w)] for i in range(h)]
mx = 0
for i in range(h):
    for j in range(w):
        mx = max(mx,D[i][j])

le = (h+w)*mx
prev = [0]*w
nex = [0]*w
prev[0]=prev[0] | 2**le
for i in range(h):
    for j in range(w):
        d = D[i][j]
        if j==0:
            nex[j] = nex[j] | prev[j]>>d |prev[j]<<d
        else:
            nex[j] = nex[j] | prev[j]>>d |prev[j]<<d
            nex[j] = nex[j] | nex[j-1]>>d |nex[j-1]<<d
        #print(i,j,d,bin(nex[j]))
    prev=nex
    nex = [0]*w
for i in range(le+1):
    if (prev[w-1]>>le+i &1) or (prev[w-1]>>le-i &1):
        print(i)
        exit()

Buggy python submission (verdict: Time Limit Exceeded):
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq

h,w = ma()
A = []
for i in range(h):
    A.append(lma())
B= []
for i in range(h):
    B.append(lma())
D = [[abs(A[i][j]-B[i][j]) for j in range(w)] for i in range(h)]
prev = [[False]*(2*80*w+1) for j in range(w)]
nex = [[False]*(2*80*w+1) for j in range(w)]
prev[0][0]=True
for i in range(h):
    for j in range(w):
        d = D[i][j]
        if j==0:
            for k in range(2*80*w+1-d):
                nex[j][k+d] = nex[j][k+d] or prev[j][k]
                nex[j][abs(k-d)] = nex[j][abs(k-d)] or prev[j][k]
        else:
            for k in range(2*80*w+1-d):
                nex[j][k+d] = nex[j][k+d] or prev[j][k] or nex[j-1][k]
                nex[j][abs(k-d)] = nex[j][abs(k-d)] or prev[j][k] or nex[j-1][k]
    prev=nex
    nex=[[False]*(2*80*w+1) for j in range(w)]
for i in range(2*80*w+1):
    if prev[w-1][i]:
        print(i)
        exit()


Fixed submission:
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq

h,w = ma()
A = []
for i in range(h):
    A.append(lma())
B= []
for i in range(h):
    B.append(lma())
D = [[abs(A[i][j]-B[i][j]) for j in range(w)] for i in range(h)]
mx = 0
for i in range(h):
    for j in range(w):
        mx = max(mx,D[i][j])

le = (h+w)*mx
prev = [0]*w
nex = [0]*w
prev[0]=prev[0] | 2**le
for i in range(h):
    for j in range(w):
        d = D[i][j]
        if j==0:
            nex[j] = nex[j] | prev[j]>>d |prev[j]<<d
        else:
            nex[j] = nex[j] | prev[j]>>d |prev[j]<<d
            nex[j] = nex[j] | nex[j-1]>>d |nex[j-1]<<d
        #print(i,j,d,bin(nex[j]))
    prev=nex
    nex = [0]*w
for i in range(le+1):
    if (prev[w-1]>>le+i &1) or (prev[w-1]>>le-i &1):
        print(i)
        exit()