#include <bits/stdc++.h>
using namespace std;

const int N = 80;
const int OFFSET = (80 + 80) * 80;

int dat[N+5][N+5];
bitset<2*OFFSET+5> dp[N+5][N+5];

int main() {
    for (int i=0; i<N+3; i++) for (int j=0; j<N+3; j++) {
        dp[i][j].reset();
    }

    dp[1][0].set(OFFSET);
    dp[0][1].set(OFFSET);

    int n,m; scanf("%d %d", &n, &m);
    for (int i=1; i<=n; i++) for (int j=1; j<=m; j++) {
        scanf("%d", &dat[i][j]);
    }

    for (int i=1; i<=n; i++) for (int j=1; j<=m; j++) {
        int a; scanf("%d", &a);
        a = abs(a - dat[i][j]);

        dp[i][j] = (
            (dp[i-1][j] << a) | (dp[i-1][j] >> a)
            | (dp[i][j-1] << a) | (dp[i][j-1] >> a)
        );
    }

    for (int i=0; i<OFFSET+2; i++) {
        if (dp[n][m][OFFSET+i] || dp[n][m][OFFSET-i]) {
            printf("%d\n", i);
            break;
        }
    }
    return 0;
}
