#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using Int = long long int;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//edit
bool reach[81][81][14000];

class Solve {
public:
    void solve() {
        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) {
            for (int j = 0; j < W; ++j) {
                cin >> A[i][j];
            }
        }

        for (int i = 0; i < H; ++i) {
            for (int j = 0; j < W; ++j) {
                cin >> B[i][j];
            }
        }

        struct cell {
            Int x, y, z;
        };
        Int zero = 80;
//        vector<vector<vector<bool>>> reach(H, vector<vector<bool>>(W, vector<bool>(162 * 82, false)));
        reach[0][0][A[0][0] - B[0][0] + zero] = true;
        reach[0][0][B[0][0] - A[0][0] + zero] = true;

        queue<cell> que;
        que.push(cell{0, 0, A[0][0] - B[0][0] + zero});
        que.push(cell{0, 0, B[0][0] - A[0][0] + zero});

        while (!que.empty()) {
            auto top = que.front();
            que.pop();
            Int h = top.x;
            Int w = top.y;
            Int z = top.z;
//            cerr << h << " " << w << " " << z << endl;

            int dh[] = {0, 1};
            int dw[] = {1, 0};

            for (int k = 0; k < 2; ++k) {
                Int nh = h + dh[k];
                Int nw = w + dw[k];
                if (nh < H && nw < W) {
                    Int nz1 = z + A[nh][nw] - B[nh][nw] + zero;
                    Int nz2 = z + B[nh][nw] - A[nh][nw] + zero;
                    if (!reach[nh][nw][nz1]) {
                        reach[nh][nw][nz1] = true;
                        que.push(cell{nh, nw, nz1});
                    }
                    if (!reach[nh][nw][nz2]) {
                        reach[nh][nw][nz2] = true;
                        que.push(cell{nh, nw, nz2});
                    }
//                    if (!reach[h][w][nz2]) {
//                        reach[h][w][nz2] = true;
//                        que.push(cell{h, w, nz2});
//                    }
                }
            }
        }
        Int ans = INFl;
//        for (int i = 0; i < reach[0][0].size(); ++i) {
        for (int i = 0; i < 14000; ++i) {
            if (reach[H - 1][W - 1][i]) {
                Int z = i - (zero * (H + W - 1));
                chmin(ans, abs(z));
            }
        }

        cout << ans << endl;

    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    Solve().solve();


    return 0;
}


Measured memory_bytes: 100224