require 'set'

H, W = gets.chomp.split(" ").map(&:to_i)
A = []
H.times{A << gets.chomp.split(" ").map(&:to_i)}
B = []
H.times{B << gets.chomp.split(" ").map(&:to_i)}

Z = 80 * (H + W)
bef = Set.new
now = Set.new
bef.add([0, 0])
now.add([0, 1])
now.add([1, 0])
D = Hash.new{|h, k| h[k] = 0}
D[[0, 0]] = 1 << (Z + A[0][0] - B[0][0])
begin
  nxt = Set.new
  now.each{|n|
    y, x = n
    c = A[y][x] - B[y][x]
    if y > 0 then
      t = [y - 1, x]
      D[n] |= D[t] << c
      D[n] |= D[t] >> c
    end
    if x > 0 then
      l = [y, x - 1]
      D[n] |= D[l] << c
      D[n] |= D[l] >> c
    end
    nxt.add([y + 1, x]) if y < H - 1
    nxt.add([y, x + 1]) if x < W - 1
  }
  bef.each{|b| D.delete(b)}
  bef = now
  now = nxt
end until(now.empty?)

a = D[[H-1, W-1]]
ans = 0
while(true) do
  break if a[Z - ans] == 1 || a[Z + ans] == 1
  ans += 1
end

puts ans
