// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

#define rep2(i,m,n) for (int i = (m); i < (n); ++i)

#define rep(i,n) rep2(i,0,n)

typedef long long int ll;

typedef long double ld;

typedef pair<int, int> P;

template<typename T> struct V : vector<T> { using vector<T>::vector; };

V() -> V<int>;

V(size_t) -> V<int>;

template<typename T> V(size_t, T) -> V<T>;

template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); }

template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); }

template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }

struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;

template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }

template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }

const int INF = 1<<30;

const ll LINF = 1LL<<61;

const ll MOD = 1000000007;

const int M = 20000;

const int C = M * 2 + 1;

typedef bitset<C> bs;



int main()

{

    int h, w;

    cin >> h >> w;

    auto a = make_vec(h,w,0), b = make_vec(h,w,0);

    rep(i,h) rep(j,w) cin >> a[i][j];

    rep(i,h) rep(j,w) cin >> b[i][j];

    // bs dp[h][w];

    auto dp = make_vec(h+1,w+1,bs(0));

    dp[0][1][M] = 1; //i,j = 0,0でのみ使われる

    rep(i,h) rep(j,w) //dp[i+1][j+1] f(dp[i+1][j], dp[i][j+1])

    {

        int d = abs(a[i][j] - b[i][j]);

        dp[i+1][j+1] |= dp[i+1][j] >> d;

        dp[i+1][j+1] |= dp[i+1][j] << d;

        dp[i+1][j+1] |= dp[i][j+1] >> d;

        dp[i+1][j+1] |= dp[i][j+1] << d;

    }

    int ans = INF;

    rep(i,C) if(dp[h][w][i]) chmin(ans, abs(i - M));

    cout << ans << endl;

    

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.131292911105446x):
#include <bits/stdc++.h>

using namespace std;

#define rep2(i,m,n) for (int i = (m); i < (n); ++i)

#define rep(i,n) rep2(i,0,n)

typedef long long int ll;

typedef long double ld;

typedef pair<int, int> P;

template<typename T> struct V : vector<T> { using vector<T>::vector; };

V() -> V<int>;

V(size_t) -> V<int>;

template<typename T> V(size_t, T) -> V<T>;

template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); }

template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); }

template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }

struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;

template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }

template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }

const int INF = 1<<30;

const ll LINF = 1LL<<61;

const ll MOD = 1000000007;

const int M = 80*80;

const int C = M * 2 + 1;

typedef bitset<C> bs;



int main()

{

    int h, w;

    cin >> h >> w;

    auto a = make_vec(h,w,0), b = make_vec(h,w,0);

    rep(i,h) rep(j,w) cin >> a[i][j];

    rep(i,h) rep(j,w) cin >> b[i][j];

    // bs dp[h][w];

    auto dp = make_vec(h+1,w+1,bs(0));

    dp[0][1][M] = 1; //i,j = 0,0でのみ使われる

    rep(i,h) rep(j,w) //dp[i+1][j+1] f(dp[i+1][j], dp[i][j+1])

    {

        int d = abs(a[i][j] - b[i][j]);

        dp[i+1][j+1] |= dp[i+1][j] >> d;

        dp[i+1][j+1] |= dp[i+1][j] << d;

        dp[i+1][j+1] |= dp[i][j+1] >> d;

        dp[i+1][j+1] |= dp[i][j+1] << d;

    }

    int ans = INF;

    rep(i,C) if(dp[h][w][i]) chmin(ans, abs(i - M));

    cout << ans << endl;

    

    return 0;

}