#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cwchar>
#include <cwctype>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <codecvt>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <shared_mutex>
#include <boost/format.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/optional.hpp>
#pragma GCC target("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef long double ld;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(int (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(12);
    int H,W;
    cin >> H >> W;
    vector<vector<int>> A(H,vector<int>(W));
    REP(i,H){
        REP(l,W){
            cin >> A[i][l];
        }
    }
    REP(i,H){
        REP(l,W){
            int bes;
            cin >> bes;
            A[i][l] = abs(A[i][l] - bes);
        }
    }
    vector<vector<vector<int>>> B(H,vector<vector<int>>(W,vector<int>(0)));
    B[0][0].eb(A[0][0]);
    REP(i,H){
        REP(l,W){
            sort(ALL(B[i][l]));
            UNIQUE(B[i][l]);
            int siz = B[i][l].size();
            if(i != H-1){
                REP(k,siz){
                    int as = B[i][l][k] + A[i+1][l];
                    int bs = abs(B[i][l][k] - A[i+1][l]);
                    if(as <= 80 * (H-i+W-l-1))B[i+1][l].eb(as);
                    if(bs <= 80 * (H-i+W-1-l))B[i+1][l].eb(bs);
                }
            }
            if(l != W-1){
                REP(k,siz){
                    if(B[i][l][k] + A[i][l+1] <= 80 * (H-i+W-1-l))B[i][l+1].eb(B[i][l][k] + A[i][l+1]);
                    if(abs(B[i][l][k] - A[i][l+1]) <= 80 * (H-i+W-1-l))B[i][l+1].eb(abs(B[i][l][k] - A[i][l+1]));
                }
            }
        }
    }
    cout << B[H-1][W-1][0] << "\n";
}

Measured memory_bytes: 282472