M=160
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)}

dp = Array.new(H+1){Array.new(W+1){Array.new(M+1)}}
dp[0][0][(A[0][0]-B[0][0]).abs]=true
dp[0][0][(B[0][0]-A[0][0]).abs]=true
H.times do |i| W.times do |j| 0.upto(M) do |d|
  next unless dp[i][j][d]
  [[i+1,j], [i,j+1]].each do |y, x|
    next unless y<H && x<W
    [(d+A[y][x]-B[y][x]).abs, (d-A[y][x]+B[y][x]).abs].each do |k|
      dp[y][x][k]=true if k<=M
    end
  end
end end end

0.upto(M) do |i|
  next unless dp[H-1][W-1][i]
  p i
  break
end
