#https://atcoder.jp/contests/abc147/submissions/8879507
H, W = gets.split.map(&:to_i)
A = H.times.map{gets.split.map(&:to_i)}
B = H.times.map{gets.split.map(&:to_i)}
M = 80*(H+W)
X = Array.new(H){Array.new(W, 0)}
H.times do |i|
  W.times do |j|
    X[i][j] = (A[i][j]-B[i][j]).abs
  end
end

dp = Array.new(H){Array.new(W, 0)}
dp[0][0] = 1 << (M - X[0][0]) | 1 << (M + X[0][0])
H.times do |i|
  W.times do |j|
    d = X[i][j]
    if i > 0
      dp[i][j] |= dp[i - 1][j] << d 
      dp[i][j] |= dp[i - 1][j] >> d
    end
    if j > 0
      dp[i][j] |= dp[i][j - 1] << d 
      dp[i][j] |= dp[i][j - 1] >> d
    end
  end
end
h = dp[H - 1][W - 1]
puts M.times.find{|i| h[M - i] > 0 || h[M + i] > 0 }