#include <sstream>
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<ctime>
#include<cmath>
#include<map>
#include<unordered_map>
#include<stack>
#include<random>
#include<queue>
#include<list>
#include<math.h>
#include<bitset>
#include<fstream>
using namespace std;
#define ll long long int
#define ld long double
#define key pair<ld,ld>
#define ii pair<int,int>
#define si set<int>
#define vii vector<pair<int,int> >
#define vi vector<int>
#define vll vector<ll>
#define vb vector<bool>
#define vvi vector<vector<int> >
#define vs vector<string>
#define all(v) v.begin(),v.end()
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define nu 100001
#define mul(x,y) ((ll)(x)*(y))%mod
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)
#define fastio  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define forn(i, n) for (int i = 0; i < int(n); i++)
const ll INF=9223372036854775807;
const ll mod=1000000007;
int  MOD(int  a, int  b)
{
    if(a>b)
        return a-b;
    else
        return b-a;
}
ll  max3(ll  a,ll  b, ll  c)
{
    return max(c,max(a,b));
}
ll min3(ll  a,ll  b,ll  c)
{
    return min(a,min(b,c));
}
ll  power(ll  x,ll  y,ll mod1)
{
    ll res = 1;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x)%mod1;
        y = y>>1;
        x = (x*x)%mod1;
    }
    return res;
}
ll logg(ll  a)
{
    ll  x=0;
    while(a>1)
    {
        x++;
        a/=2;
    }
    return x;
}
ll  gcd(ll  a,ll   b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
ll abso(ll x)
{
    if(x<0)
    {
        return -x;
    }
    return x;
}
ll ceiling (ll  a,ll  b)
{
    if(a%b==0)
    {
        return a/b;
    }
    else
    {
        return a/b+1;
    }
}
ll modinv(ll x,ll p)
{
    return power(x,p-2,p);
}
int main()
{
    fastio;
    int h,w;
    cin>>h>>w;
    int grid[81][81][2];
    for(int k=0;k<2;k++){
        for(int i=0;i<h;i++)
        {
            for(int j=0;j<w;j++)
            {
                cin>>grid[i][j][k];
                
            }
        }
    }
    char dp[81][81][4*81*81];
    for(int k=0;k<=2*160*80;k++)
    {
        dp[h-1][w-1][k]=0;
    }
    dp[h-1][w-1][2*80*80+grid[h-1][w-1][0]-grid[h-1][w-1][1]]=1;
    dp[h-1][w-1][2*80*80-grid[h-1][w-1][0]+grid[h-1][w-1][1]]=1;
    
    for(int i=h-1;i>=0;i--)
    {
        for(int j=w-1;j>=0;j--)
        {
            for(int k=-160*80;k<=160*80;k++)
            {
                k+=160*80;
                if(i+1<h){
                    if(k+grid[i][j][0]-grid[i][j][1]>=0&&k+grid[i][j][0]-grid[i][j][1]<=2*160*80){
                        
                        dp[i][j][k]=dp[i+1][j][k+grid[i][j][0]-grid[i][j][1]];}
                    if(k+grid[i][j][1]-grid[i][j][0]>=0&&k+grid[i][j][1]-grid[i][j][0]<=2*160*80){
                        dp[i][j][k]=(dp[i][j][k]+dp[i+1][j][k+grid[i][j][1]-grid[i][j][0]]);}
                }
                if(j+1<w)
                {
                    if(k+grid[i][j][0]-grid[i][j][1]>=0&&k+grid[i][j][0]-grid[i][j][1]<=2*160*80){
                        dp[i][j][k]=(dp[i][j][k]+dp[i][j+1][k+grid[i][j][0]-grid[i][j][1]]);}
                    if(k+grid[i][j][1]-grid[i][j][0]>=0&&k+grid[i][j][1]-grid[i][j][0]<=2*160*80){
                        dp[i][j][k]=(dp[i][j][k]+dp[i][j+1][k+grid[i][j][1]-grid[i][j][0]]);
                    }
                }
                dp[i][j][k]=min(dp[i][j][k],(char)1);
                k-=160*80;
            }
        }
    }
    ll ans=160*80;
    for(int k=0;k<=2*160*80;k++)
    {
        if(dp[0][0][k]==1)
        {
            ans=min((ll)ans,abso(k-160*80));
        }
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 168320