using System;
using System.Linq;
using CompLib.Util;

public class Program
{
    int H, W;
    long[] A;
    public void Solve()
    {
        var sc = new Scanner();
        H = sc.NextInt();
        W = sc.NextInt();
        A = new long[H * W];
        for (int i = 0; i < H * W; i++)
        {
            A[i] += sc.NextInt();
        }
        for (int i = 0; i < H * W; i++)
        {
            A[i] -= sc.NextInt();
        }

        var t = 80 * (80 + 80 - 1);
        var dp = new bool[H * W, 2 * t + 1];


        for (int i = 0; i < H; i++)
        {
            for (int j = 0; j < W; j++)
            {
                if (i == 0 && j == 0)
                {
                    dp[0, A[0] + t] = true;
                }
                else
                {
                    if (i - 1 >= 0)
                    {
                        for (int b = 0; b <= 2 * t; b++)
                        {
                            if (dp[C(i - 1, j), b])
                            {
                                // Console.WriteLine($"{i} {j} {b} {t}");
                                dp[C(i, j), b + A[C(i, j)]] = true;
                                dp[C(i, j), b - A[C(i, j)]] = true;
                            }
                        }
                    }

                    if (j - 1 >= 0)
                    {
                        for (int b = 0; b <= 2 * t; b++)
                        {
                            if (dp[C(i, j - 1), b])
                            {
                                dp[C(i, j), b + A[C(i, j)]] = true;
                                dp[C(i, j), b - A[C(i, j)]] = true;
                            }
                        }
                    }
                }
            }
        }

        int ans = int.MaxValue;
        for (int i = 0; i <= 2 * t; i++)
        {
            if (dp[C(H - 1, W - 1), i])
            //if (dp[0, i])
            {

                ans = Math.Min(ans, Math.Abs(i - t));
            }
        }

        Console.WriteLine(ans);
    }

    public int C(int i, int j)
    {
        return i * W + j;
    }

    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            if (_index >= _line.Length)
            {
                string s;
                do
                {
                    s = Console.ReadLine();
                } while (s.Length == 0);

                _line = s.Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public string ReadLine()
        {
            _index = _line.Length;
            return Console.ReadLine();
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            string s = Console.ReadLine();
            _line = s.Length == 0 ? new string[0] : s.Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


Measured memory_bytes: 132508