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

bool dp[81][81][2*81*81];
int main(){
   int h,w; cin>>h>>w;
   vector<vector<int>> A(h,vector<int>(w));
   vector<vector<int>> B(h,vector<int>(w));
   for(int i = 0; i < h; i++)for(int j = 0; j < w; j++) cin>>A[i][j];
   for(int i = 0; i < h; i++)for(int j = 0; j < w; j++) cin>>B[i][j];
   
   dp[0][0][abs(A[0][0]-B[0][0])] = true;

   for(int i = 0; i < h; i++)for(int j = 0; j < w; j++)for(int k = 0;  k < (2*81*81); k++){
       if(!dp[i][j][k]) continue;
       if(i<h-1){
           int c = abs(A[i+1][j] - B[i+1][j]);
           dp[i+1][j][abs(k+c)] = true;
           dp[i+1][j][abs(k-c)] = true;
       }
       if(j<w-1){
         int c = abs(A[i][j+1] - B[i][j+1]);
        dp[i][j+1][abs(k+c)] = true;
        dp[i][j+1][abs(k-c)] = true;
       }
   }
   int ans = 1e9;
   for(int i = 0; i < 2*81*81; i++){
       if(dp[h-1][w-1][i]) ans = min(ans,i);
   }
  cout<<ans;
}
