// Original C++ solution (slower):
#include <algorithm>

#include <bitset>

#include <climits>

#include <cmath>

#include <csignal>

#include <cstdio>

#include <cstdlib>

#include <functional>

#include <iomanip>

#include <iostream>

#include <map>

#include <queue>

#include <set>

#include <string>

#include <tuple>

#include <vector>



using Graph = std::vector<std::vector<int>>;

using WGraph = std::vector<std::vector<std::pair<int, long long>>>;

using ll = long long;

using namespace std;



constexpr int bit_size = 80*159+1;



int main() {

    int h = 0, w = 0;

    cin >> h >> w;

    vector<vector<int>> a(h, vector<int>(w));

    for (int i=0; i<h; i++) {

        for (int j=0; j<w; j++) {

            cin >> a.at(i).at(j);

        }

    }

    vector<vector<int>> b(h, vector<int>(w));

    for (int i=0; i<h; i++) {

        for (int j=0; j<w; j++) {

            cin >> b.at(i).at(j);

        }

    }



    vector<vector<int>> field(h, vector<int>(w));

    for (int i=0; i<h; i++) {

        for (int j=0; j<w; j++) {

            field.at(i).at(j) = abs(a.at(i).at(j) - b.at(i).at(j));

        }

    }

    

    vector<vector<vector<bool>>> dp(h, vector<vector<bool>>(w, vector<bool>(bit_size, false)));

    dp.at(0).at(0).at(field.at(0).at(0)) = true; 

    for (int i=0; i<h; i++) {

        for (int j=0; j<w; j++) {

            for (int k=0; k<bit_size; k++) {

                if (dp.at(i).at(j).at(k)) {

                    if (i != h-1) {

                        int tmp = field.at(i+1).at(j);

                        dp.at(i+1).at(j).at(k+tmp) = true;

                        dp.at(i+1).at(j).at(abs(k-tmp)) = true;

                    }

                    if (j != w-1) {

                        int tmp = field.at(i).at(j+1);

                        dp.at(i).at(j+1).at(k+tmp) = true;

                        dp.at(i).at(j+1).at(abs(k-tmp)) = true;

                    }

                }

            }

        }

    }



    for (int i=0; i<bit_size; i++) {

        if (dp.at(h-1).at(w-1).at(i)) {

            cout << i << endl;

            break;

        }

    }



    return 0;

}


// Optimized solution to the same problem (faster):
#include <algorithm>

#include <bitset>

#include <climits>

#include <cmath>

#include <csignal>

#include <cstdio>

#include <cstdlib>

#include <functional>

#include <iomanip>

#include <iostream>

#include <map>

#include <queue>

#include <set>

#include <string>

#include <tuple>

#include <vector>



using Graph = std::vector<std::vector<int>>;

using WGraph = std::vector<std::vector<std::pair<int, long long>>>;

using ll = long long;

using namespace std;



constexpr int bit_size = 80*159+1;



int main() {

    int h = 0, w = 0;

    cin >> h >> w;

    vector<vector<int>> a(h, vector<int>(w));

    for (int i=0; i<h; i++) {

        for (int j=0; j<w; j++) {

            cin >> a.at(i).at(j);

        }

    }

    vector<vector<int>> b(h, vector<int>(w));

    for (int i=0; i<h; i++) {

        for (int j=0; j<w; j++) {

            cin >> b.at(i).at(j);

        }

    }



    vector<vector<int>> field(h, vector<int>(w));

    for (int i=0; i<h; i++) {

        for (int j=0; j<w; j++) {

            field.at(i).at(j) = abs(a.at(i).at(j) - b.at(i).at(j));

        }

    }

    

    vector<vector<bitset<bit_size>>> dp(h, vector<bitset<bit_size>>(w));

    dp.at(0).at(0).set(field.at(0).at(0)); 

    for (int i=0; i<h; i++) {

        for (int j=0; j<w; j++) {

            if (i != h-1) {

                int tmp = field.at(i+1).at(j);

                dp.at(i+1).at(j) |= (dp.at(i).at(j) << tmp);

                dp.at(i+1).at(j) |= (dp.at(i).at(j) >> tmp);

                for (int k=0; k<tmp; k++) {

                    if (dp.at(i).at(j).test(k)) {

                        dp.at(i+1).at(j).set(tmp-k);

                    }

                }

            }

            if (j != w-1) {

                int tmp = field.at(i).at(j+1);

                dp.at(i).at(j+1) |= (dp.at(i).at(j) << tmp);

                dp.at(i).at(j+1) |= (dp.at(i).at(j) >> tmp);

                for (int k=0; k<tmp; k++) {

                    if (dp.at(i).at(j).test(k)) {

                        dp.at(i).at(j+1).set(tmp-k);

                    }

                }

            }

        }

    }



    for (int i=0; i<bit_size; i++) {

        if (dp.at(h-1).at(w-1).test(i)) {

            cout << i << endl;

            break;

        }

    }



    return 0;

}


// Fastest known solution for this problem: