#include <iostream>
                                    #include <iomanip>
                                    #include <sstream>
                                    #include <cstring>
                                    #include <vector>
                                    #include <deque>
                                    #include <queue>
                                    #include <set>
                                    #include <map>
                                    #include <valarray>
                                    #include <iterator>
                                    #include <functional>
                                    #include <limits>
                                    #include <algorithm>
                                    #include <numeric>
                                    #include <cmath>
                                    #include <cassert>
                                    #include <unordered_map>
                                    #include <unordered_set>
                                    #include <stack>
                                    using namespace std;
                                    #define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
                                     #define trace(x) cerr << #x << ": " << x << " " << endl;
                                 
                                    typedef int64_t ll;
                                 
                                    #define endl '\n'
                                    //#define int ll
                                    ll mod=1e9+7;
                                    ll mod1=1e9+5;
                                    
                                    ll power(ll a,ll b)
                                    {
                                        if(b==0) return 1;
                                        else if(b%2==0)
                                            return power((((a%mod)*(a%mod))%mod),b/2)%mod;
                                        else return ((a%mod)*(power((((a%mod)*(a%mod))%mod),b/2)%mod))%mod;
                                    }
                                    
                                  
                                
                                 bool dp[80][80][51201];
                                int main()
                                {
                                    IOS
                             
                                
                                int n,m;
                                cin>>n>>m;
                                int a[n][m];
                                int b[n][m];
                                memset(a,0,sizeof(a));
                                memset(b,0,sizeof(b));
                                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];
                                }
                                int base=12800;
                                memset(dp,false,sizeof(dp));
                                dp[0][0][a[0][0]-b[0][0]+base]=1;
                                dp[0][0][-a[0][0]+b[0][0]+base]=1;
                                for(int i=0;i<n;++i)
                                {
                                    for(int j=0;j<m;++j)
                                    {
                                        if(i!=0)
                                        {
                                            for(int k=51200;k>=0;--k)
                                            {
                                                if(dp[i-1][j][k])
                                                    dp[i][j][a[i][j]-b[i][j]+k]=1;
                                                if(dp[i-1][j][k])
                                                    dp[i][j][-a[i][j]+b[i][j]+k]=1;
                                            }
                                        }
                                        if(j!=0)
                                        {
                                            for(int k=51200;k>=0;--k)
                                            {
                                                if(dp[i][j-1][k])
                                                    dp[i][j][a[i][j]-b[i][j]+k]=1;
                                                if(dp[i][j-1][k])
                                                    dp[i][j][-a[i][j]+b[i][j]+k]=1;
                                            }
                                        }
                                        

                                    }
                                }
                                int ans=1e9;
                                for(int k=51200;k>=0;--k)
                                {
                                    if(dp[n-1][m-1][k])
                                    ans=min(ans,abs(k-base));
                                }

                                cout<<ans;
                                


                                }                       


Measured memory_bytes: 320256