#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

const int DMAX = 160*80+5;
bool dp[85][85][DMAX];
int main() {
  int h,w;
  cin >> h >> w;
  vector<vector<int>> a(h,vector<int>(w));
  vector<vector<int>> b(h,vector<int>(w));
  rep(i,h)rep(j,w) cin >> a[i][j];
  rep(i,h)rep(j,w) cin >> b[i][j];


  dp[1][0][0] = dp[0][1][0] = true;
  rep(i,h)rep(j,w){
    int nd = abs(a[i][j] - b[i][j]);
    rep(d,DMAX){
      if(dp[i][j+1][d]){
        dp[i+1][j+1][d+nd] = true;
        dp[i+1][j+1][abs(d-nd)] = true;
      }
      if(dp[i+1][j][d]){
        dp[i+1][j+1][d+nd] = true;
        dp[i+1][j+1][abs(d-nd)] = true;
      }
    }
  }
  
  rep(i,DMAX){
    if(dp[h][w][i]){
      cout << i << endl; 
      break;
    }
  }

}
