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

MAX_LEN = 200
C = [[]]
H.times{|h|
  c = [0]
  W.times{|w|
    c << A[h][w] - B[h][w]
  }
  C << c
}

bef = Set.new
bef.add([1, 1])
D = Hash.new{|h, k| h[k] = []}
D[[1, 1]] << C[1][1]
until(bef.empty?) do
  nxt = Set.new
  bef.each{|b|
    if b[0] < H then
      nb = b.dup
      nb[0] += 1
      nxt.add(nb)
      D[nb] += D[b].map{|d| d += C[nb[0]][nb[1]]}
      D[nb] += D[b].map{|d| d -= C[nb[0]][nb[1]]}
    end
    if b[1] < W then
      nb = b.dup
      nb[1] += 1
      nxt.add(nb)
      D[nb] += D[b].map{|d| d += C[nb[0]][nb[1]]}
      D[nb] += D[b].map{|d| d -= C[nb[0]][nb[1]]}
    end
  }
  nxt.each{|n|
    D[n] = D[n].uniq.sort_by{|b| b.abs}
    D[n] = D[n][0, MAX_LEN] if D[n].size > MAX_LEN
  }
  bef.each{|b| D.delete(b) if b != [H, W]}
  bef = nxt
end

puts D[[H, W]][0].abs
