import Foundation

class Scanner {
    static func readInt() -> Int {
        return Int(readLine()!)!
    }
    
    static func readIntArr() -> [Int] {
        return readLine()!.split(separator: " ").map { Int($0)! }
    }
    
    static func readM(_ n: Int) -> [[Int]] {
        var res = [[Int]]()
        for _ in 0..<n {
            res.append(readIntArr())
        }
        return res
    }
    
    static func readUknownIntMat() -> [[Int]] {
        var res = [[Int]]()
        while let line = readLine() {
            res.append(line.split(separator: " ").map { Int($0)! })
        }
        return res
    }
    
    static func readString() -> String {
        return readLine()!
    }
}

class Printer {
    static func printIntArray(_ arr: [Int]) {
        print(arr.map { String($0) }.joined(separator: " "))
    }
}

let nm = Scanner.readIntArr()
let mat1 = Scanner.readM(nm[0]*2)
var mat = [[[Int]]](repeating: [[Int]](repeating: [Int](repeating: 0, count: 2),
                                       count: nm[1]),
                    count: nm[0])
for i in stride(from: 0, to: nm[0], by: 1) {
    for j in stride(from: 0, to: nm[1], by: 1) {
        mat[i][j][0] = mat1[i][j]
        mat[i][j][1] = mat1[i+nm[0]][j]
    }
}




class Solution {
    var mat: [[[Int]]]!
    var n = 0, m = 0
    var dp = [[[Int]]](repeating: [[Int]](repeating: [Int](repeating: -1, count: 6500), count: 81), count: 81)
    
    func balancedPath(_ mat: [[[Int]]], _ n: Int, _ m: Int) -> Int {
        self.n = n
        self.m = m
        self.mat = mat
        return dfs(0,0,0)
    }
    
    func dfs(_ row: Int,
             _ col: Int,
             _ val: Int) -> Int {
        guard row < n && col < m else {
            return 512000
        }
        
        guard dp[row][col][val] == -1 else {
            return dp[row][col][val]
        }
        
        let point = abs(mat[row][col][0]-mat[row][col][1])
        if row == n-1 && col == m-1 {
            return min(abs(val-point), abs(val+point))
        }
        
        var one = 512000
        var two = 512000
        var three = 512000
        var four = 512000
            
        if row + 1 < mat.count {
            one = dfs(row+1, col, abs(val-point))
            if abs(val+point) < 6400 {
                two = dfs(row+1, col, abs(val+point))
            }
            
        }
        if col + 1 < mat[0].count {
            three = dfs(row, col+1, abs(val-point))
            if abs(val+point) < 6400 {
                four = dfs(row, col+1, abs(val+point))
            }
            
        }
        dp[row][col][val] = min(one, two, three, four)
        return dp[row][col][val]
    }
    
}

//print(mat)
print(Solution().balancedPath(mat, nm[0], nm[1]))
