/*
* @Author: SugarSBN
* @Date: 2018-05-21 21:54:00
* @Language: C++
* @Task: chess
*/
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<queue>
#include<stack>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<cmath>
#include<sstream>
#include<fstream>
using namespace std;
const int MAXN=1e5+11;
const double pi=acos(-1);
const int inf = 2e7;
const int base = 12;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef double dbl;
#define For(a,b,c) for (int (a)=(b);(a)<(c);(a)++)
#define foreach(iter,V) for (__typeof((V.begin()) iter=(V).begin();iter!=(V).end();iter++)
#define mp make_pair
#define fi first
#define se second
#define pb push_back
int n, m;
int a[15][15], b[15][15], hei[15];
map<ll, int> mapp;
ll hashs(){
ll res = 0;
For(i, 1, n + 1) res = res * base + hei[i];
return res;
}
void unzip(ll x){
for (int i = n; i ; i--) {
hei[i] = x % base;
x /= base;
}
}
bool maxn_or_minn(){
ll res = 0;
For(i, 1, n + 1) res += hei[i];
return res & 1;
}
int dfs(ll sta){
if (mapp.find(sta)!=mapp.end())
return mapp[sta];
unzip(sta);
bool tpe = maxn_or_minn();
int ret = tpe ? inf : -inf;
For(i, 1, n + 1)
if (hei[i - 1] > hei[i]){
++hei[i];
ll h = hashs();
if (!tpe)
ret = max(ret, dfs(h) + a[i][hei[i]]);
else
ret = min(ret, dfs(h) - b[i][hei[i]]);
--hei[i];
}
return mapp[sta] = ret;
}
int main(){
scanf("%d%d", &n, &m);
hei[0] = m;
For(i, 0, n)
For(j, 0, m) scanf("%d", &a[i+1][j+1]);
For(i, 0, n)
For(j, 0, m) scanf("%d", &b[i+1][j+1]);
For(i, 1, n + 1) hei[i] = m;
ll full = hashs();
mapp[full] = 0;
dfs(0);
printf("%d\n", mapp[0]);
return 0;
}