#include <iostream>
#include <cstring>
#include <cmath>
#include <bitset>
using namespace std;
const int N = 100;
const int M = 6401;
const int Y = 6400;
int H, W, A[N][N], B[N][N];
bitset<M*2> dp[N][N];


int main(){
    cin >> H >> W;
    for (int i = 1; i <= H; i++){
        for (int j = 1; j <= W; j++){
            cin >> A[i][j];
        }
    }
    for (int i = 1; i <= H; i++){
        for (int j = 1; j <= W; j++){
            cin >> B[i][j];
        }
    }
    dp[0][1][Y] = dp[1][0][Y] = 1;
    for (int i = 1; i <= H; i++){
        for (int j = 1; j <= W; j++){
            int cha = abs(A[i][j] - B[i][j]);
            dp[i][j] |= ((dp[i-1][j] << cha)|(dp[i-1][j] >> cha));
            dp[i][j] |= ((dp[i][j-1] << cha)|(dp[i][j-1] >> cha));
        }
    }
    int ans = INT32_MAX;
    for (int i = 0; i < 2*M; i++){
        if (dp[H][W][i]) ans = min(ans, abs(i-Y));
    }
    cout << ans << endl;
    return 0;
}
