H, W = gets.split.map(&:to_i)
A = Array.new(H){Array.new(W, 0)}
[1, -1].each do |c|
    H.times do |i|
        arr = gets.split.map(&:to_i)
        W.times do |j|
            A[i][j] += arr[j] * c
        end
    end
end

M = 160*80
dp = Array.new(H){Array.new(W, 0)}
dp[0][0] = 1 << M
H.times do |i|
    W.times do |j|
        dp[i][j] |= dp[i-1][j] if i > 0
        dp[i][j] |= dp[i][j-1] if j > 0
        dp[i][j] = (dp[i][j] << A[i][j]) | (dp[i][j] >> A[i][j])
    end
end

ans = M
(2*M).times do |i|
    ans = [ans, (M-i).abs].min if dp[H-1][W-1][i] == 1
end
puts ans
