// Slower C++ solution:
#include <bits/stdc++.h>



using namespace std;

using int64 = long long;



constexpr int DEBUG = 0;



template<typename T>

vector<vector<T>> Make2DVector(int d1, int d2, T default_value) {

  return vector<vector<T>>(d1, vector<T>(d2, default_value));

}



template<typename T>

vector<vector<vector<T>>> Make3DVector(int d1, int d2, int d3, T default_value) {

  return vector<vector<vector<T>>>(d1, vector<vector<T>>(d2, vector<T>(d3, default_value)));

}



template<class T> inline bool UpdateMin(T& a, T b) {

  if (a > b) { a = b; return 1; } return 0;

}



template<class T> inline bool UpdateMax(T& a, T b) {

  if (a < b) { a = b; return 1; } return 0;

}



int main() {

  ios::sync_with_stdio(false);

  cin.tie(0);



  constexpr int BASE = 12800;

  int h, w;

  cin >> h >> w;



  auto v1_table = Make2DVector(h, w, 0);

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

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

      cin >> v1_table[y][x];

    }

  }

  auto v2_table = Make2DVector(h, w, 0);

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

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

      cin >> v2_table[y][x];

    }

  }



  auto dp = Make3DVector(h, w, 2 * BASE + 1, 0);

  dp[0][0][BASE + v1_table[0][0] - v2_table[0][0]] = 1;

  dp[0][0][BASE - v1_table[0][0] + v2_table[0][0]] = 1;

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

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

      if (y - 1 >= 0) {

        for (int k = 0; k <= 2 * BASE; k++) {

          if (dp[y - 1][x][k]) {

            dp[y][x][k + v1_table[y][x] - v2_table[y][x]] = 1;

            dp[y][x][k - v1_table[y][x] + v2_table[y][x]] = 1;

          }

        }

      }



      if (x - 1 >= 0) {

        for (int k = 0; k <= 2 * BASE; k++) {

          if (dp[y][x - 1][k]) {

            dp[y][x][k + v1_table[y][x] - v2_table[y][x]] = 1;

            dp[y][x][k - v1_table[y][x] + v2_table[y][x]] = 1;

          }

        }

      }

    }

  }



  int ans = INT32_MAX;

  for (int k = 0; k <= 2 * BASE; k++) {

    if (dp[h - 1][w - 1][k]) {

      UpdateMin(ans, abs(BASE - k));

    }

  }

  cout << ans << endl;

}


// Faster C++ solution for the same problem (measured speedup: 1.6654586397464506x):
#include <bits/stdc++.h>



using namespace std;

using int64 = long long;



constexpr int DEBUG = 0;



template<typename T>

vector<vector<T>> Make2DVector(int d1, int d2, T default_value) {

  return vector<vector<T>>(d1, vector<T>(d2, default_value));

}



template<typename T>

vector<vector<vector<T>>> Make3DVector(int d1, int d2, int d3, T default_value) {

  return vector<vector<vector<T>>>(d1, vector<vector<T>>(d2, vector<T>(d3, default_value)));

}



template<class T> inline bool UpdateMin(T& a, T b) {

  if (a > b) { a = b; return 1; } return 0;

}



template<class T> inline bool UpdateMax(T& a, T b) {

  if (a < b) { a = b; return 1; } return 0;

}



int main() {

  ios::sync_with_stdio(false);

  cin.tie(0);



  constexpr int BASE = 12800;

  int h, w;

  cin >> h >> w;



  auto v1_table = Make2DVector(h, w, 0);

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

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

      cin >> v1_table[y][x];

    }

  }

  auto v2_table = Make2DVector(h, w, 0);

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

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

      cin >> v2_table[y][x];

    }

  }



  auto dp = Make3DVector<char>(h, w, 2 * BASE + 1, 0);

  dp[0][0][BASE + v1_table[0][0] - v2_table[0][0]] = 1;

  dp[0][0][BASE - v1_table[0][0] + v2_table[0][0]] = 1;

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

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

      if (y - 1 >= 0) {

        for (int k = 0; k <= 2 * BASE; k++) {

          if (dp[y - 1][x][k]) {

            dp[y][x][k + v1_table[y][x] - v2_table[y][x]] = 1;

            dp[y][x][k - v1_table[y][x] + v2_table[y][x]] = 1;

          }

        }

      }



      if (x - 1 >= 0) {

        for (int k = 0; k <= 2 * BASE; k++) {

          if (dp[y][x - 1][k]) {

            dp[y][x][k + v1_table[y][x] - v2_table[y][x]] = 1;

            dp[y][x][k - v1_table[y][x] + v2_table[y][x]] = 1;

          }

        }

      }

    }

  }



  int ans = INT32_MAX;

  for (int k = 0; k <= 2 * BASE; k++) {

    if (dp[h - 1][w - 1][k]) {

      UpdateMin(ans, abs(BASE - k));

    }

  }

  cout << ans << endl;

}