// Original C++ solution (slower):
#include<iostream>

#include<vector>

#define lli long long int

#include<climits>

#define pb push_back

using namespace std;





int main()

{

    

    int h,w,i,j;

    cin>>h>>w;

    

    vector<vector<int>>dp1(h+1,vector<int>(w+1));

    vector<vector<int>>dp2(h+1,vector<int>(w+1));

    vector<vector<int>>dp3(h+1,vector<int>(w+1));

    

    for(i=1;i<=h;i++)

        for(j=1;j<=w;j++)

            cin>>dp1[i][j];

    

    for(i=1;i<=h;i++)

        for(j=1;j<=w;j++)

            cin>>dp2[i][j];

    

    for(i=1;i<=h;i++)

        for(j=1;j<=w;j++)

            dp3[i][j] = abs(dp1[i][j]-dp2[i][j]);

    

    vector<vector<vector<int>>>dp(h+1,vector<vector<int>>(w+1,vector<int>(12801,0)));

    

    dp[h][w][abs(dp3[h][w])] = 1;

    

    for(i=h,j=w-1;j>=1;j--)

        for(int k=0;k<=12801;k++)

            if(dp[i][j+1][k]==1)

            {

                dp[i][j][abs(k+dp3[i][j])] = 1;

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

            }

    

    for(i=h-1;i>=1;i--)

    {

        for(j=w;j>=1;j--)

        {

            if(j==w)

            {

                for(int k=0;k<=12801;k++)

                    if(dp[i+1][j][k]==1)

                    {

                        dp[i][j][abs(k+dp3[i][j])] = 1;

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

                    }

            }

            

            else

            {

                for(int k=0;k<=12801;k++)

                {

                    if(dp[i+1][j][k]==1)

                    {

                        dp[i][j][abs(k+dp3[i][j])] = 1;

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

                    }

                    if(dp[i][j+1][k]==1)

                    {

                        dp[i][j][abs(k+dp3[i][j])] = 1;

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

                    }

                }

            

            }

        }

    }

    

    

    int mymin = INT_MAX;

    for(int k=0;k<=12801;k++)

    {

        if(dp[1][1][k]==1) mymin = min(k,mymin);

        

    }

    cout<<mymin<<endl;

    

    

    

}




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



using namespace std;



int n, m;

int a[101][101], b[101][101];

bitset<20001> f[101][101];



int main(int argc, char** argv)

{

	ios::sync_with_stdio(false);

	cin.tie(0);

	cout.tie(0);



	cin >> n >> m;

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

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

			cin >> a[i][j];

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

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

			cin >> b[i][j];

	f[1][1].set(10000);

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

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

		{

			int v1 = a[i][j] - b[i][j];

			int v2 = b[i][j] - a[i][j];

			if (v1 >= 0)

			{

				f[i + 1][j] |= (f[i][j] << v1);

				f[i][j + 1] |= (f[i][j] << v1); 

			}	

			else

			{

				v1 = -v1;

				f[i + 1][j] |= (f[i][j] >> v1);

				f[i][j + 1] |= (f[i][j] >> v1); 

			}	

			if (v2 >= 0)

			{

				f[i + 1][j] |= (f[i][j] << v2);

				f[i][j + 1] |= (f[i][j] << v2);

			}

			else

			{

				v2 = -v2;

				f[i + 1][j] |= (f[i][j] >> v2);

				f[i][j + 1] |= (f[i][j] >> v2);

			}	

		}

	int ans = 1e9;

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

		if (f[n][m].test(i))

		{       

			int v1 = i + a[n][m] - b[n][m];

			int v2 = i + b[n][m] - a[n][m];

			ans = min(ans, min(abs(v1 - 10000), abs(v2 - 10000)));

		} 

	cout << ans;	

}

// Fastest known solution for this problem: