// Original C++ solution (slower):
//#include "pch.h"

#include <iostream>

#include <algorithm>

#include <map>

#include <set>

#include <queue>

#include <bitset>

#include <limits.h>

#include <string>

#include <deque>

#include <cmath>

#include <bitset>



using namespace std;

typedef long long ll;

typedef pair<int, int> P;



#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)

#define mpa make_pair

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



bool dp[80][80][13000];

vector<vector<int>> da(80,vector<int>(80));



int main(){

    int h,w;

    cin >> h >> w;

    rip(i,h,0){

        rip(j,w,0){

            cin >> da[i][j];

        }

    }

    int jjj;

    rip(i,h,0){

        rip(j,w,0){

            cin >> jjj;

            da[i][j] = abs(da[i][j] - jjj);

        }

    }

    rip(i,h,0){

        rip(j,w,0){

            rip(k,13000,0){

                dp[i][j][k] = false;

            }

        }

    }

    dp[0][0][da[0][0]] = true;

    rip(i,h,0){

        rip(j,w,0){

            rip(k,12800,0){

                if(i){

                    if(dp[i- 1][j][k + da[i][j]]){

                        dp[i][j][k] = true;

                    }

                    if(dp[i -1][j][abs(k - da[i][j])]){

                        dp[i][j][k] = true;

                    }

                }

                if(j){

                    if(dp[i][j - 1][k + da[i][j]]){

                        dp[i][j][k] = true;

                    }

                    if(dp[i][j - 1][abs(k - da[i][j])]){

                        dp[i][j][k] = true;

                    }

                }

            }

        }

    }

    int ans = 0;

    while(!dp[h - 1][w -1][ans]){

        ans++;

    }

    cout << ans << endl;

}

// Optimized solution to the same problem (faster):
//#include "pch.h"

#include <iostream>

#include <algorithm>

#include <map>

#include <set>

#include <queue>

#include <bitset>

#include <limits.h>

#include <string>

#include <deque>

#include <cmath>

#include <bitset>



using namespace std;

typedef long long ll;

typedef pair<int, int> P;



#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)

#define mpa make_pair

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



int h, w;

int da[81][81];

bitset<8000> dp[81][81];



int main(){

    cin >> h >> w;

    rip(i, h + 1, 1){

        rip(j, w + 1, 1){

            cin >> da[i][j];

        }

    }

    int b;

    rip(i, h + 1, 1){

        rip(j, w + 1, 1){

            cin >> b;

            da[i][j] = abs(da[i][j] - b);

        }

    }

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

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

    rip(i, h + 1, 1){

        rip(j, w + 1, 1){

            dp[i][j] |= (dp[i - 1][j] << da[i][j]);

            dp[i][j] |= (dp[i][j - 1] << da[i][j]);

            dp[i][j] |= (dp[i - 1][j] >> da[i][j]);

            dp[i][j] |= (dp[i][j - 1] >> da[i][j]);

            rip(k ,da[i][j], 0){

                dp[i][j][abs(k - da[i][j])] = (dp[i][j][abs(k - da[i][j])] | (dp[i - 1][j][k] | dp[i][j - 1][k]));

            }

        }

    }

    int ans = 0;

    /*rip(i, h + 1, 0){

        rip(j ,w + 1, 0){

            if(j == w){

                cout << dp[i][j] << endl;

            }

            else{

                cout << dp[i][j] << ' ';

            }

        }

    }*/

    while(!dp[h][w][ans]){

        ans ++;

    }

    cout << ans << endl;

}

// Fastest known solution for this problem: