import java.math.*

fun main(args: Array<String>) {
    val (H, W) = readInputLine().split(" ").map { it.toInt() }
    val AArr = Array(H) { readInputLine().split(" ").map { it.toInt() }.toIntArray() }
    val BArr = Array(H) { readInputLine().split(" ").map { it.toInt() }.toIntArray() }

    val diffArr = Array(H) { h -> IntArray(W) { w -> Math.abs(AArr[h][w] - BArr[h][w]) } }
    
    val dp = Array(H) { Array(W) { BooleanArray(6500) }}
    dp[0][0][diffArr[0][0]] = true

    for (i in 0 until H) {
        for (j in 0 until W) {
            for (k in 0 until 6400) {
                if (!dp[i][j][k]) {
                    continue
                }
                if (i != H - 1) {
                    dp[i + 1][j][k + diffArr[i + 1][j]] = true
                    dp[i + 1][j][Math.abs(k - diffArr[i + 1][j])] = true
                }
                if (j != W - 1) {
                    dp[i][j + 1][k + diffArr[i][j + 1]] = true
                    dp[i][j + 1][Math.abs(k - diffArr[i][j + 1])] = true
                }
            }
        }
    }
    
    for (i in 0 until 6400) {
        if (dp[H - 1][W - 1][i]) {
            println(i)
            return
        }
    }
}

fun readInputLine(): String {
    return readLine()!!
}
