#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int H, W;
    cin >> H >> W;
    v2int A(H, vint(W));
    v2int B(H, vint(W));
    rep(i, H) {
        rep(j, W) {
            cin >> A[i][j];
        }
    }
    rep(i, H) {
        rep(j, W) {
            cin >> B[i][j];
        }
    }
    int offset = 80 * 100;
    vector<vector<vector<bool>>> dp(H, vector<vector<bool>>(W, vector<bool>(80 * 400 + 1, false)));
    dp[0][0][A[0][0] - B[0][0] + offset] = true || dp[0][0][A[0][0] - B[0][0] + offset];
    dp[0][0][-A[0][0] + B[0][0] + offset] = true || dp[0][0][-A[0][0] + B[0][0] + offset];
    int ans = INF;
    rep(i, H) {
        //if (i + 1 >= H) continue;
        rep(j, W) {
            REP(k, -offset,  80 * 200 + 1 - offset) {
                if (i + 1 < H) {
                    if (k - ((A[i + 1][j] - B[i + 1][j])) + offset >= 0 && k - (A[i + 1][j] - B[i + 1][j]) + offset <= 80 * 400)
                        dp[i + 1][j][k + offset] = (dp[i + 1][j][k + offset] || dp[i][j][k - ((A[i + 1][j] - B[i + 1][j])) + offset]);
                    if (k - ((-A[i + 1][j] + B[i + 1][j])) + offset >= 0 && k - (-A[i + 1][j] + B[i + 1][j]) + offset <= 80 * 400)
                        dp[i + 1][j][k + offset] = (dp[i + 1][j][k + offset] || dp[i][j][k - ((-A[i + 1][j] + B[i + 1][j])) + offset]);
                }
                if (j + 1 < W) {
                    if (k - ((A[i][j + 1] - B[i][j + 1])) + offset >= 0 && k - (A[i][j + 1] - B[i][j + 1]) + offset <= 80 * 400)
                        dp[i][j + 1][k + offset] = (dp[i][j + 1][k + offset] || dp[i][j][k - ((A[i][j + 1] - B[i][j + 1])) + offset]);
                    if (k - ((-A[i][j + 1] + B[i][j + 1])) + offset >= 0 && k - (-A[i][j + 1] + B[i][j + 1]) + offset <= 80 * 400)
                        dp[i][j + 1][k + offset] = (dp[i][j + 1][k + offset] || dp[i][j][k - ((-A[i][j + 1] + B[i][j + 1])) + offset]);
                }
            }
        }
    }
    rep(k, 80 * 400 + 1) {
        if (dp[H - 1][W - 1][k] == true)
            ans = min(ans, abs(k - offset));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 29048