/* imports all std modules {{{*/
import
  std.algorithm,
  std.array,
  std.ascii,
  std.base64,
  std.bigint,
  std.bitmanip,
  std.compiler,
  std.complex,
  std.concurrency,
  std.container,
  std.conv,
  std.csv,
  std.datetime,
  std.demangle,
  std.encoding,
  std.exception,
  std.file,
  std.format,
  std.functional,
  std.getopt,
  std.json,
  std.math,
  std.mathspecial,
  std.meta,
  std.mmfile,
  std.net.curl,
  std.net.isemail,
  std.numeric,
  std.parallelism,
  std.path,
  std.process,
  std.random,
  std.range,
  std.regex,
  std.signals,
  std.socket,
  std.stdint,
  std.stdio,
  std.string,
  std.system,
  std.traits,
  std.typecons,
  std.uni,
  std.uri,
  std.utf,
  std.uuid,
  std.variant,
  std.zip,
  std.zlib;
/*}}}*/

/* libnum {{{*/
void amax(N, Args...)(ref N x, Args y) {
  x = x.max(y);
}
void amin(N, Args...)(ref N x, Args y) {
  x = x.min(y);
}
auto maxE(R)(R r) if (isInputRange!R) {
  ElementType!R x = r.front;
  r.popFront();
  foreach (y; r) x.amax(y);
  return x;
}
auto minE(R)(R r) if (isInputRange!R) {
  ElementType!R x = r.front;
  r.popFront();
  foreach (y; r) x.amin(y);
  return x;
}
/*}}}*/

/+---test
2 2
1 2
3 4
3 4
2 1
---+/
/+---test
2 3
1 10 80
80 10 1
1 2 3
4 5 6
---+/

void main(string[] args) {
  long H, W;
  readf(" %d %d ", &H, &W);

  auto map = new long[][](H, W);
  foreach (ref row; map) {
    const a = readln.split.map!(to!long).array;
    row[] = a[];
  }
  foreach (ref row; map) {
    const b = readln.split.map!(to!long).array;
    foreach (i; 0..W) row[i] = abs(row[i] - b[i]);
  }

  const max_diff = (H+W)*80;
  auto  dp       = new bool[][][](H, W, max_diff*2);

  dp[0][0][max_diff+map[0][0]] = true;
  dp[0][0][max_diff-map[0][0]] = true;
  foreach (y; 0..H) foreach (x; 0..W) foreach (s; 0..max_diff*2) {
    if (dp[y][x][s]) {
      if (y+1 < H) {
        dp[y+1][x][s+map[y+1][x]] = true;
        dp[y+1][x][s-map[y+1][x]] = true;
      }
      if (x+1 < W) {
        dp[y][x+1][s+map[y][x+1]] = true;
        dp[y][x+1][s-map[y][x+1]] = true;
      }
    }
  }
  zip(iota(-max_diff, max_diff), dp[$-1][$-1]).
    filter!"a[1]".
    map!(x => x[0].abs).
    minElement.
    writeln;
}
