// Original C++ solution (slower):
//Compete against Yourself.

#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;

#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

#define pb push_back

#define sz(i) (int)(i.size())

#define F first

#define S second

#define L long double

#define P pair<int, int>

const int mod = (int)1e9 + 7;

using namespace std;

#if LOCAL

#include "../../tr.h"

#else

#define tr(...)

#define endl '\n'

#endif

template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}

const int N = 80;



int n, m, a[N][N], b[N][N];

gp_hash_table<int, int> dp[N][N];



void add(int x, int y, int red, int blue){

   if(x-1 >= 0){

      for(auto it: dp[x-1][y]){

         dp[x][y][abs(it.F+(red-blue))] = 1;

         dp[x][y][abs(it.F-(red-blue))] = 1;

      }

   }

   if(y-1 >= 0){

      for(auto it: dp[x][y-1]){

         dp[x][y][abs(it.F+(red-blue))] = 1;

         dp[x][y][abs(it.F-(red-blue))] = 1;

      }

   }

   if(x-1 < 0 and y-1 < 0){

      dp[x][y][abs(red-blue)] = 1;

   }

}





int32_t main(){_



   cin>>n>>m;



   for (int i = 0; i < n; ++i)

   {

      for (int j = 0; j < m; ++j)

      {

         cin >> a[i][j];

      }

   }



   for (int i = 0; i < n; ++i)

   {

      for (int j = 0; j < m; ++j)

      {

         cin >> b[i][j];

      }

   }



   for (int i = 0; i < n; ++i)

   {

      for (int j = 0; j < m; ++j)

      {

         add(i, j, a[i][j], b[i][j]);

      }  

   }

   

   int ans = 2e9;

   for(auto it: dp[n-1][m-1]){

      smin(ans, it.F);

   }



   cout<<ans;



   return 0;

}


// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;



//#define int long long

#define fi first

#define se second

#define sz(x) (int)(x).size()

#define all(x) (x).begin(), (x).end()

#define yn(x) ((x) ? "Yes" : "No")



typedef pair <int, int> ii;

typedef pair <int, ii> iii;



const int siz = 80 + 1;

const int SIZ = 2 * 6400 + 1;

const int mod = 1e9 + 7;

const int maxx = 2e9;

const int MAXX = 1e18;

const string file = "1";



int a[siz][siz];

bool f[siz][siz][SIZ];



int32_t main() {

    ios::sync_with_stdio(0);

    cin.tie(0); cout.tie(0);



//    freopen ((file + ".inp").c_str(), "r", stdin);

//    freopen ((file + ".out").c_str(), "w", stdout);



    int m, n;

    cin >> m >> n;

    for (int i = 1; i <= m; i++) {

        for (int j = 1; j <= n; j++) {

            cin >> a[i][j];

        }

    }



    for (int i = 1; i <= m; i++) {

        for (int j = 1; j <= n; j++) {

            int x;

            cin >> x;



            a[i][j] = abs(a[i][j] - x);

        }

    }



    f[1][1][a[1][1]] = true;

    for (int i = 1; i <= m; i++) {

        for (int j = 1; j <= n; j++) {

            for (int k = 0; k < SIZ; k++) {

                if (f[i][j][k] == true) {

                    if (i < m) {

                        f[i + 1][j][abs(k - a[i + 1][j])] = true;

                        f[i + 1][j][k + a[i + 1][j]] = true;

                    }



                    if (j < n) {

                        f[i][j + 1][abs(k - a[i][j + 1])] = true;

                        f[i][j + 1][k + a[i][j + 1]] = true;

                    }

                }

            }

        }

    }



    for (int k = 0; k < SIZ; k++) {

        if (f[m][n][k] == true) {

            return cout << k << "\n", 0;

        }

    }



//    cerr << "Time: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";



    return 0;

}


// Fastest known solution for this problem: