require 'set'
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).map{ Array.new(w).map{ Set.new } }

dp[0][0].add((a[0][0] - b[0][0]).abs)

h.times do |i|
    w.times do |j|
        dp[i][j].each do |k|
            dp[i + 1][j].add(k + (a[i + 1][j] - b[i + 1][j]).abs) if i + 1 < h
            dp[i + 1][j].add((k - (a[i + 1][j] - b[i + 1][j]).abs).abs) if i + 1 < h
            dp[i][j + 1].add(k + (a[i][j + 1] - b[i][j + 1]).abs) if j + 1 < w
            dp[i][j + 1].add((k - (a[i][j + 1] - b[i][j + 1]).abs).abs) if j + 1 < w
        end
    end
end

puts dp[h - 1][w - 1].min