#include<bits/stdc++.h>

using namespace std;
#define ll long long
#define ull unsigned long long
#define mp make_pair
typedef pair<int, int> pii;
typedef priority_queue<int, vector<int>, greater<int> > small_heap;
typedef priority_queue<int> big_heap;
int a[100][100], b[100][100];
bool dp[100][100][25609];
int n, m;

int main() {
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)scanf("%d", &a[i][j]);
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)scanf("%d", &b[i][j]);
    dp[1][1][a[1][1] - b[1][1] + 12800] = 1;
    dp[1][1][b[1][1] - a[1][1] + 12800] = 1;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            if (i == 1 && j == 1)continue;
            for (int k = 0; k <= 25600; k++) {
                int temp1 = a[i][j] - b[i][j];
                int temp2 = b[i][j] - a[i][j];
                if (dp[i - 1][j][k - temp1] || dp[i - 1][j][k - temp2])dp[i][j][k] = 1;
                if (dp[i][j - 1][k - temp1] || dp[i][j - 1][k - temp2])dp[i][j][k] = 1;
            }
        }
    }
    int s = 12800, e = 12800;
    while (1) {
        if (dp[n][m][s] || dp[n][m][e])break;
        e++;
        s--;
    }
    printf("%d\n", e - 12800);
    return 0;
}