#include<bits/stdc++.h>
using namespace std;
#define INFS (1LL<<28)
#define INF (1LL<<60)
#define DEKAI 1000000007
//#define MOD 1000000007
#define lp(i,n) for(int i=0;i<n;i++)
#define lps(i,n) for(int i=1;i<=n;i++)
#define all(c) begin(c), end(c)

//#define int long long 

namespace {
#define __DECLARE__(C)    \
    template <typename T> \
    std::ostream &operator<<(std::ostream &, const C<T> &);

#define __DECLAREM__(C)               \
    template <typename T, typename U> \
    std::ostream &operator<<(std::ostream &, const C<T, U> &);

__DECLARE__(std::vector)
__DECLARE__(std::deque)
__DECLARE__(std::set)
__DECLARE__(std::stack)
__DECLARE__(std::queue)
__DECLARE__(std::priority_queue)
__DECLARE__(std::unordered_set)
__DECLAREM__(std::map)
__DECLAREM__(std::unordered_map)

template <typename T, typename U>
std::ostream &operator<<(std::ostream &, const std::pair<T, U> &);
template <typename... T>
std::ostream &operator<<(std::ostream &, const std::tuple<T...> &);
template <typename T, std::size_t N>
std::ostream &operator<<(std::ostream &, const std::array<T, N> &);

template <typename Tuple, std::size_t N>
struct __TuplePrinter__ {
    static void print(std::ostream &os, const Tuple &t) {
        __TuplePrinter__<Tuple, N - 1>::print(os, t);
        os << ", " << std::get<N - 1>(t);
    }
};

template <typename Tuple>
struct __TuplePrinter__<Tuple, 1> {
    static void print(std::ostream &os, const Tuple &t) { os << std::get<0>(t); }
};

template <typename... T>
std::ostream &operator<<(std::ostream &os, const std::tuple<T...> &t) {
    os << '(';
    __TuplePrinter__<decltype(t), sizeof...(T)>::print(os, t);
    os << ')';
    return os;
}

template <typename T, typename U>
std::ostream &operator<<(std::ostream &os, const std::pair<T, U> &v) {
    return os << '(' << v.first << ", " << v.second << ')';
}

#define __INNER__                             \
    os << '[';                                \
    for (auto it = begin(c); it != end(c);) { \
        os << *it;                            \
        os << (++it != end(c) ? ", " : "");   \
    }                                         \
    return os << ']';

template <typename T, std::size_t N>
std::ostream &operator<<(std::ostream &os, const std::array<T, N> &c) {
    __INNER__
}

#define __DEFINE__(C)                                           \
    template <typename T>                                       \
    std::ostream &operator<<(std::ostream &os, const C<T> &c) { \
        __INNER__                                               \
    }

#define __DEFINEM__(C)                                             \
    template <typename T, typename U>                              \
    std::ostream &operator<<(std::ostream &os, const C<T, U> &c) { \
        __INNER__                                                  \
    }

#define __DEFINEW__(C, M1, M2)                                  \
    template <typename T>                                       \
    std::ostream &operator<<(std::ostream &os, const C<T> &c) { \
        std::deque<T> v;                                        \
        for (auto d = c; !d.empty(); d.pop()) v.M1(d.M2());     \
        return os << v;                                         \
    }

__DEFINE__(std::vector)
__DEFINE__(std::deque)
__DEFINE__(std::set)
__DEFINEW__(std::stack, push_front, top)
__DEFINEW__(std::queue, push_back, front)
__DEFINEW__(std::priority_queue, push_front, top)
__DEFINE__(std::unordered_set)
__DEFINEM__(std::map)
__DEFINEM__(std::unordered_map)
}


bool dp[100][100][15000];
int done[100][100];
#define int long long 

signed main(){
	int h,w;
	cin>>h>>w;
	int a[100][100],b[100][100];
	lp(i,h){
		lp(j,w){
			cin>>a[i][j];
		}
	}
	lp(i,h){
		lp(j,w){
			cin>>b[i][j];
		}
	}
	queue<pair<int,int>> q;
	dp[0][0][7500]=1;
	q.push({0,0});
	while(!q.empty()){
		int nh=q.front().first;
		int nw=q.front().second;
		q.pop();
		if(done[nh][nw]==1)continue;
		done[nh][nw]=1;
		if(nh!=h-1){
			q.push({nh+1,nw});
		}
		if(nw!=w-1){
			q.push({nh,nw+1});
		}
		lp(i,15000){
			int now=i-7500;
			if(dp[nh][nw][i]==1){
				//cout<<nh<<" "<<nw<<" "<<now<<endl;
				int nex=i+(a[nh][nw]-b[nh][nw]);
				//cout<<nex<<endl;
				if(nex<0||nex>=15000)1;
				else{
					dp[nh+1][nw][nex]=1;
					dp[nh][nw+1][nex]=1;
				} 
				nex=i+(b[nh][nw]-a[nh][nw]);
				if(nex<0||nex>=15000)1;
				else{
					dp[nh+1][nw][nex]=1;
					dp[nh][nw+1][nex]=1;
				}
				//cout<<nex<<endl;
			}
		}
	}
	int ans=DEKAI;
	lp(i,15000){
		if(dp[h][w-1][i]==1){
			ans=min(ans,abs(i-7500));
		}
		if(dp[h-1][w][i]==1){
			ans=min(ans,abs(i-7500));
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 118272