// Slower C++ solution:
// 見せてやるぜ、奇跡ってやつをよぉ……

#include <iostream>

#include <array>

#include <algorithm>

#include <vector>

#include <set>

#include <unordered_set>

#include <cmath>

#include <complex>

#include <deque>

#include <iterator>

#include <numeric>

#include <map>

#include <unordered_map>

#include <queue>

#include <stack>

#include <string>

#include <tuple>

#include <utility>

#include <limits>

#include <iomanip>

#include <functional>

#include <cassert>

using namespace std;



using ll=long long;

template<class T> using V = vector<T>;

template<class T, class U> using P = pair<T, U>;

using vll = V<ll>;

using vvll = V<vll>;

#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)

#define REP(i, n) rep(i, 0, n)

#define ALL(v) v.begin(),v.end()

template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }

template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }

#define DEBUG_VLL(vec) REP(sz, vec.size()) cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');



const ll MOD = 1000000007;

const ll HIGHINF = (ll)1e18;



int main() {

    cin.tie(0);

    ios::sync_with_stdio(false);

    ll h, w; cin >> h >> w;

    vvll a(h, vll(w)), b(h, vll(w));

    REP(i, h) REP(j, w) cin >> a[i][j];

    REP(i, h) REP(j, w) cin >> b[i][j];

    V< vvll > dp(h, vvll(w, vll(160 * 80 + 1)));

    dp[0][0][abs(a[0][0] - b[0][0])] = 1;

    REP(i, h) REP(j, w) {

        REP(k, 160 * 80 + 1) {

            if (i - 1 >= 0) {

                if (dp[i - 1][j][k] == 1) {

                    dp[i][j][k + abs(a[i][j] - b[i][j])] = 1;

                    dp[i][j][abs(k - abs(b[i][j] - a[i][j]))] = 1;

                }

            }

            if (j - 1 >= 0) {

                if (dp[i][j - 1][k] == 1) {

                    dp[i][j][k + abs(a[i][j] - b[i][j])] = 1;

                    dp[i][j][abs(k - abs(b[i][j] - a[i][j]))] = 1;

                }

            }

        }

    }

    REP(i, 160 * 80 + 1) {

        if (dp[h - 1][w - 1][i] == 1) {

            cout << i << '\n';

            break;

        }

    }

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.374298422955638x):
#include <iostream>

#include <array>

#include <algorithm>

#include <vector>

#include <bitset>

#include <set>

#include <unordered_set>

#include <cmath>

#include <complex>

#include <deque>

#include <iterator>

#include <numeric>

#include <map>

#include <unordered_map>

#include <queue>

#include <stack>

#include <string>

#include <tuple>

#include <utility>

#include <limits>

#include <iomanip>

#include <functional>

#include <cassert>

using namespace std;



using ll=long long;

template<class T> using V = vector<T>;

template<class T, class U> using P = pair<T, U>;

using vll = V<ll>;

using vvll = V<vll>;

#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)

#define REP(i, n) rep(i, 0, n)

#define ALL(v) v.begin(),v.end()

template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }

template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }

#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');



const long long MOD = 1000000007;

const long long HIGHINF = (long long)1e18;

const int INF = (int)1e9;



int h, w;

V< V<int> > a, b;



int main() {

    cin.tie(0);

    ios::sync_with_stdio(false);

    cin >> h >> w;

    a.resize(h, V<int>(w)), b.resize(h, V<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];

        }

    }



    const int maxk = 160 * 80 + 1;

    V< V< V<int> > > dp(h, V< V<int> >(w, V<int>(maxk, 0)));

    dp[0][0][abs(a[0][0] - b[0][0])] = 1;

    for (int i = 0; i < h; i++) {

        for (int j = 0; j < w; j++) {

            for (int k = 0; k < maxk; k++) {

                if (i > 0) {

                    if (dp[i - 1][j][k] == 1) {

                        dp[i][j][k + abs(a[i][j] - b[i][j])] = 1;

                        dp[i][j][abs(k - abs(b[i][j] - a[i][j]))] = 1;

                    }

                }

                if (j > 0) {

                    if (dp[i][j - 1][k] == 1) {

                        dp[i][j][k + abs(a[i][j] - b[i][j])] = 1;

                        dp[i][j][abs(k - abs(b[i][j] - a[i][j]))] = 1;

                    }

                }

            }

        }

    }



    for (int k = 0; k < maxk; k++) {

        if (dp[h - 1][w - 1][k] == 1) {

            cout << k << '\n';

            break;

        }

    }

    return 0;

}