import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}
import scala.collection.mutable.{Map, Stack, Queue, PriorityQueue, Set}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val H, W = in.next().toInt
  val A = Array.ofDim[Int](H+1, W+1)
  val B = Array.ofDim[Int](H+1, W+1)
 
  for (y <- 1 to H; x <- 1 to W) {
    A(y)(x) = in.next().toInt
  }
  for (y <- 1 to H; x <- 1 to W) {
    B(y)(x) = in.next().toInt
  }


  //
  val V = 80*(H+W)

  val dp = Array.ofDim[Boolean](H+1, W+1, V*2+1)
  dp(0)(1)(V) = true
  dp(1)(0)(V) = true

  for {
    y <- 1 to H
    x <- 1 to W
    c = (A(y)(x) - B(y)(x)).abs
    v <- 0 to V*2
  } {
    if (dp(y-1)(x)(v) || dp(y)(x-1)(v)) {
      dp(y)(x)(v + c) = true
      dp(y)(x)(v - c) = true
    }
  }

  var ans = 0
  breakable {
    var i = 0
    val last = dp(H)(W)
    while (true) {
      if (last(V-i) || last(V+i)) {
        ans = i
        break
      }
      i += 1
    }
  }

  println(ans)
}

object Sub {
  def print2DimArray[A](mat: Array[Array[A]]): Unit = {
    mat.foreach(lin => println(lin.toList))
  }
}

class InputReader(stream: InputStream) {
  private[this] val reader = new BufferedReader(new InputStreamReader(stream))
  private[this] var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}
