Problem:
Score : 500 points

Problem Statement

We have a grid with H horizontal rows and W vertical columns. Let (i,j) denote the square at the i-th row from the top and the j-th column from the left.

The square (i, j) has two numbers A_{ij} and B_{ij} written on it.

First, for each square, Takahashi paints one of the written numbers red and the other blue.

Then, he travels from the square (1, 1) to the square (H, W). In one move, he can move from a square (i, j) to the square (i+1, j) or the square (i, j+1). He must not leave the grid.

Let the unbalancedness be the absolute difference of the sum of red numbers and the sum of blue numbers written on the squares along Takahashi's path, including the squares (1, 1) and (H, W).

Takahashi wants to make the unbalancedness as small as possible by appropriately painting the grid and traveling on it.

Find the minimum unbalancedness possible.

Constraints

2 \leq H \leq 80

2 \leq W \leq 80

0 \leq A_{ij} \leq 80

0 \leq B_{ij} \leq 80

All values in input are integers.

Input

Input is given from Standard Input in the following format:

H W
A_{11} A_{12} \ldots A_{1W}
:
A_{H1} A_{H2} \ldots A_{HW}
B_{11} B_{12} \ldots B_{1W}
:
B_{H1} B_{H2} \ldots B_{HW}

Output

Print the minimum unbalancedness possible.

Sample Input 1

2 2
1 2
3 4
3 4
2 1

Sample Output 1

0

By painting the grid and traveling on it as shown in the figure below, the sum of red numbers and the sum of blue numbers are 3+3+1=7 and 1+2+4=7, respectively, for the unbalancedness of 0.

Sample Input 2

2 3
1 10 80
80 10 1
1 2 3
4 5 6

Sample Output 2

2

Solution in C# (Mono 4.6.2.0) (judge verdict: Time Limit Exceeded)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Runtime.CompilerServices;
using ll=System.Int64;

public class Contest
{
	static void Swap1<T>(ref T a, ref T b) { T t = a; a = b; b = t; }
	static void Swap2<T>(ref T a, ref T b) where T : IComparable { if (a.CompareTo(b)==1) Swap1(ref a, ref b); }  // b の方が小さければ交換
	static bool Chmin<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b)== 1) { a = b; return true; } return false; }  // b の方が小さければ a を更新
	static bool Chmax<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b)==-1) { a = b; return true; } return false; }  // b の方が大きければ a を更新
	static T[][] InitMat<T>(long len1, long len2, T val){ T[][] m = new T[len1][]; for (int i = 0; i < m.Length; i++) m[i] = Enumerable.Repeat(val, (int)len2).ToArray(); return m; }
	static T[][][] InitMat<T>(long len1, long len2, long len3, T val){ T[][][] m = new T[len1][][]; for (int i = 0; i < m.Length; i++) m[i] = InitMat(len2,len3,val); return m; }
	public const long MOD1 = 1000000007; // 10^9+7
	public const double EPS1 = 1e-8;

	public static void Main() {
		Solve_E();
 	}

	public static void Solve_A() {
		long  n, m, o;
		MyIO.ReadMulti(out n, out m, out o);
		string ans = "win";
		if(22<=n+m+o) ans = "bust";



		MyIO.WriteMulti(ans);
	}
	public static void Solve_B() {
		string s;
		MyIO.ReadMulti(out s);
		long ans = 0;
		for (int i = 0; i < s.Length/2; i++)
		{
			if(s[i]!=s[s.Length-i-1]) ans++;
		}

		MyIO.WriteMulti(ans);
	}
	public static void Solve_C() {
		int  n;
		MyIO.ReadMulti(out n);

		VT<int,int>[][] ss = new VT<int, int>[n][];
		for (int i = 0; i < n; i++)
		{
			long a;
			MyIO.ReadMulti(out a);
			MyIO.ReadLines(a, out ss[i]);
		}

		long ans = 0;
		for (int i = 0; i < 1<<n; i++)
		{
			int[] tlist = new int[n];
			bool pass = true; 
			int cnt = 0;
			for (int j = 0; j < n; j++)
			{
				tlist[j] = (i>>j)&1;
				if(tlist[j]==1) cnt++;
			}
			for (int j = 0; j < n; j++)
			{
				if(tlist[j]==1){
					for (int k = 0; k < ss[j].Length; k++)
					{
						if(tlist[ss[j][k].Item1-1]!=ss[j][k].Item2){
							pass = false;
							break;
						}
					}
				}
				if(!pass){
					break;
				}
			}
			if(pass){
				Chmax(ref ans, cnt);
			}

		}

		MyIO.WriteMulti(ans);
	}
	public static void Solve_D() {
		long  n;
		MyIO.ReadMulti(out n);
		ll[] a;
		MyIO.ReadArray(out a);


		long ans = 0;



		MyIO.WriteMulti(ans);
	}
	public static void Solve_E() {
		long  h, w;
		MyIO.ReadMulti(out h, out w);
		ll[][] a,b;
		MyIO.ReadMatrix(h, out a);
		MyIO.ReadMatrix(h, out b);
		ll maxv = 0;
		for (int i = 0; i < h; i++)
		{
			for (int j = 0; j < w; j++)
			{
				Chmax(ref maxv, Math.Abs((a[i][j]-b[i][j])));
			}
		}
		ll kmax = (maxv+2)*(h+w);
		bool[][][] dp = InitMat(h+1,w+1,kmax,false);
		dp[0][0][a[0][0]-b[0][0]+kmax/2] = true;
		dp[0][0][b[0][0]-a[0][0]+kmax/2] = true;
		for (int i = 0; i < h; i++)
		{
			for (int j = 0; j < w; j++)
			{
				if(i==0&&j==0)continue;

				for (int k = 0; k < kmax; k++)
				{
					if (!dp[i][j][k]) dp[i][j][k] = (0<i&&0<=k-(a[i][j]-b[i][j])&&k-(a[i][j]-b[i][j])<kmax)? dp[i-1][j][k-(a[i][j]-b[i][j])] : false;
					if (!dp[i][j][k]) dp[i][j][k] = (0<i&&0<=k-(b[i][j]-a[i][j])&&k-(b[i][j]-a[i][j])<kmax)? dp[i-1][j][k-(b[i][j]-a[i][j])] : false;
					if (!dp[i][j][k]) dp[i][j][k] = (0<j&&0<=k-(a[i][j]-b[i][j])&&k-(a[i][j]-b[i][j])<kmax)? dp[i][j-1][k-(a[i][j]-b[i][j])] : false;
					if (!dp[i][j][k]) dp[i][j][k] = (0<j&&0<=k-(b[i][j]-a[i][j])&&k-(b[i][j]-a[i][j])<kmax)? dp[i][j-1][k-(b[i][j]-a[i][j])] : false;
				}
			}
		}


		long ans = int.MaxValue;
		for (int k = 0; k<=kmax/2; k++)
		{
			if(dp[h-1][w-1][kmax/2+k]||dp[h-1][w-1][kmax/2-k]){
				ans = k;
				break;
			}
		}


		MyIO.WriteMulti(ans);
	}
	public static void Solve_F() {
		long  n, m;
		MyIO.ReadMulti(out n, out m);



		long ans = 0;


		MyIO.WriteMulti(ans);
	}












}




















#region MyIO

public struct VT<T, U>
{
	public T Item1; public U Item2;
    public VT(T a, U b) { Item1 = a; Item2 = b; }
}
public struct VT<T, U, V>
{
	public T Item1; public U Item2; public V Item3;
    public VT(T a, U b, V c) { Item1 = a; Item2 = b; Item3 = c; }
}
public struct VT<T, U, V, W>
{
	public T Item1; public U Item2; public V Item3; public W Item4;
    public VT(T a, U b, V c, W d) { Item1 = a; Item2 = b; Item3 = c; Item4 = d; }
}

public class Printer : System.IO.StreamWriter
{
	public override IFormatProvider FormatProvider { get { return System.Globalization.CultureInfo.InvariantCulture; } }
	public Printer(System.IO.Stream stream) : base(stream, new UTF8Encoding(false, true)) { }
	public Printer(System.IO.Stream stream, Encoding encoding) : base(stream, encoding) { }
}
public static class MyIO
{
	private static char[] splitter = new char[] {' '};
	private static bool eq<T, U>() => typeof(T).Equals(typeof(U));
	private static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
	private static T cv<T>(string s) =>
		eq<T, int>()    ? ct<T, int>(int.Parse(s))
	  : eq<T, long>()   ? ct<T, long>(long.Parse(s))
	  : eq<T, double>() ? ct<T, double>(double.Parse(s, System.Globalization.CultureInfo.InvariantCulture))
	  : eq<T, char>()   ? ct<T, char>(s[0])
						: ct<T, string>(s);
			
	public static string[] ReadMulti<T>(out T a) {
		var ar = Console.ReadLine().Split(splitter, StringSplitOptions.RemoveEmptyEntries); 
		a = cv<T>(ar[0]);
		return ar;
	}
	public static string[] ReadMulti<T, U>(out T a, out U b) {
		var ar = ReadMulti<T>(out a); 
        b = cv<U>(ar[1]);
		return ar;
	}
	public static string[] ReadMulti<T, U, V>(out T a, out U b, out V c) {
		var ar = ReadMulti<T, U>(out a, out b); 
        c = cv<V>(ar[2]);
		return ar;
	}
	public static string[] ReadMulti<T, U, V, W>(out T a, out U b, out V c, out W d) {
		var ar = ReadMulti<T, U, V>(out a, out b, out c); 
        d = cv<W>(ar[3]);
		return ar;
	}
	public static string[] ReadMulti<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) {
		var ar = ReadMulti<T, U, V, W>(out a, out b, out c, out d); 
        e = cv<X>(ar[4]);
		return ar;
	}
	public static string[] ReadMulti<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f) {
		var ar = ReadMulti<T, U, V, W, X>(out a, out b, out c, out d, out e); 
        f = cv<Y>(ar[5]);
		return ar;
	}
	public static string[] ReadArray<T>(out T[] a) {		
		var ar = Console.ReadLine().Split(splitter, StringSplitOptions.RemoveEmptyEntries);
		a = ar.Select(cv<T>).ToArray();
		return ar;
	}		
	public static string[][] ReadLines<T>(long n, out T[] a) {
		a = new T[n];
		string[][] arr = new string[n][];
		for(int i=0; i<n; i++) arr[i] = ReadMulti(out a[i]);
		return arr;
	}
	public static string[][] ReadLines<T, U>(long n, out VT<T, U>[] a) {
		a = new VT<T, U>[n];
		string[][] arr = new string[n][];
		for(int i=0; i<n; i++) {
			T o; U p;
			arr[i] = ReadMulti(out o, out p);
			a[i] = new VT<T, U>(o, p);
		}
		return arr;
	}
	public static string[][] ReadLines<T, U, V>(long n, out VT<T, U, V>[] a) {
		a = new VT<T, U, V>[n];
		string[][] arr = new string[n][];
		for(int i=0; i<n; i++) {
			T o; U p; V q;
			arr[i] = ReadMulti(out o, out p, out q);
			a[i] = new VT<T, U, V>(o, p, q);
		}
		return arr;
	}
	public static string[][] ReadLines<T, U, V, W>(long n, out VT<T, U, V, W>[] a) {
		a = new VT<T, U, V, W>[n];
		string[][] arr = new string[n][];
		for(int i=0; i<n; i++) {
			T o; U p; V q; W r;
			arr[i] = ReadMulti(out o, out p, out q, out r);
			a[i] = new VT<T, U, V, W>(o, p, q, r);
		}
		return arr;
	}
	public static string[][] ReadMatrix<T>(long n, out T[][] a) {
		a = new T[n][];
		string[][] arr = new string[n][];
		for(int i=0; i<n; i++) arr[i] = ReadArray(out a[i]);
		return arr;
	}

	private static void wwp(Action act){
		var sw = new Printer(Console.OpenStandardOutput()){AutoFlush = false};
		Console.SetOut(sw);
		act();
		Console.Out.Flush();
		sw.AutoFlush = true;
		Console.SetOut(sw);
	}
	private static string wfm(Type t) =>t.Equals(typeof(double)) ? "{0:F10}" : "{0}";
	public static void WriteMulti(params object[] a) {
		wwp(()=>{
			for(int i=0;i<a.Length;i++) {
				string fs = wfm(a[i].GetType()) + ((i<a.Length-1) ? " " : Environment.NewLine);
				Console.Write(fs, a[i]);
			}
		});
	}
	public static void WriteArray<T>(T[] a) {
		wwp(()=>{
			string fs = wfm(typeof(T));
			string fs1 = fs + " ";
			string fs2 = fs + Environment.NewLine;
			for(int i=0;i<a.Length;i++) Console.Write( ((i<a.Length-1) ? fs1 : fs2), a[i]);
		});
	}
	public static void WriteLines<T>(T[] a) {
		wwp(()=>{
			string fs = wfm(typeof(T)) + Environment.NewLine;
			foreach(T x in a) Console.Write(fs, x);
		});
	}


}

#endregion