#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) {
    if (a > b || a == -1) {
        a = b;
        return 1;
    }
    return 0;
}

template<class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template<class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template<class T, class V>
typename enable_if<is_class<T>::value == 0>::type fill(T &t, const V &v) {
    t = v;
}
template<class T, class V>
typename enable_if<is_class<T>::value != 0>::type fill(T &t, const V &v){
    for (auto &e : t) fill(e, v);
}

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }

#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }


const int MAX = 90;
const int GETA = 15000;
int H, W;
int A[90][90];
int B[90][90];

bool dp[90][90][GETA*2];
int solve() {
    memset(dp, 0, sizeof(dp));
    dp[0][0][GETA+A[0][0]-B[0][0]] = true;
    dp[0][0][GETA+B[0][0]-A[0][0]] = true;
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            for (int v = 0; v < GETA*2; ++v) {
                if (!dp[i][j][v]) continue;
                
                dp[i+1][j][v + A[i+1][j] - B[i+1][j]] = true;
                dp[i+1][j][v + B[i+1][j] - A[i+1][j]] = true;
                dp[i][j+1][v + A[i][j+1] - B[i][j+1]] = true;
                dp[i][j+1][v + B[i][j+1] - A[i][j+1]] = true;
                /*
                }
                if (v - B[i+1][j] >= 0) {
                    dp[i+1][j][v-B[i+1][j]] = true;
                }

                if (v + A[i][j+1] < GETA*2) {
                    dp[i][j+1][v+A[i][j+1]] = true;
                }
                if (v - B[i][j+1] >= 0) {
                    dp[i][j+1][v-B[i][j+1]] = true;
                }   
                */
            }
        }
    }
    int res = GETA*2;
    for (int v = 0; v < GETA*2; ++v) {
        if (!dp[H-1][W-1][v]) continue;
        res = min(res, abs(v-GETA));
    }
    return res;
}

int main() {
    while (cin >> H >> 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];
        cout << solve() << endl;
    }
}

        














Measured memory_bytes: 237568