#include <bits/stdc++.h>

using namespace std;

int main(){
    int h, w;
    cin >> h >> w;
    vector<vector<int>> A(h, vector<int>(w)), B(h, vector<int>(w));
    for (int i = 0; i < h; i++)
        copy_n(istream_iterator<int>(cin), w, A[i].begin());

    for (int i = 0; i < h; i++)
        copy_n(istream_iterator<int>(cin), w, B[i].begin());

    const int sup = 1e5;
    vector<vector<bitset<sup>>> M(h + 1, vector<bitset<sup>>(w + 1));

    M[0][0][sup / 2] = true;
    for (int i = 0; i < h; i++){
        for (int j = 0; j < w; j++){
            int c = abs(A[i][j] - B[i][j]);
            M[i + 1][j] |= M[i][j] << c;
            M[i + 1][j] |= M[i][j] >> c;
            M[i][j + 1] |= M[i][j] << c;
            M[i][j + 1] |= M[i][j] >> c;
        }
    }

    int ans = 1e9;
    for (int k = 0; k < sup; k++){
        if (M[h - 1][w][k])
            ans = min(ans, abs(k - sup / 2));
    }

    cout << ans << endl;
}