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]]]!
    //80*80*80*2
    
    var dp = [[[Int]]](repeating: [[Int]](repeating: [Int](repeating: -1, count: 2), count: 84), count: 84)
    
    func balancedPath(_ mat: [[[Int]]]) -> Int {
        self.mat = mat
        return min(abs(dfs(0,0,true)), abs(dfs(0,0,false)))
    }
    
    func dfs(_ row: Int,
             _ col: Int,
             _ blue: Bool) -> Int {
        guard row < mat.count && col < mat[0].count else {
            return 522000
        }
        
        guard dp[row][col][(blue ? 0 : 1)] == -1 else {
            return dp[row][col][(blue ? 0 : 1)]
        }
        
        let curCell = mat[row][col]
        let point = curCell[0]-curCell[1]
        if row == mat.count-1 && col == mat[0].count-1 {
            return blue ? point : -point
        }
        var res = point
        var diff = Int.max
        if row+1 < mat.count {
            let downBlue = dfs(row+1, col, true)
            let downNotBlue = dfs(row+1, col, false)
            
            
            if abs((blue ? abs(point) : -abs(point)) + downBlue) < diff {
                diff = abs((point * (blue ? 1 : -1)) + downBlue)
                res = (blue ? abs(point) : -abs(point)) + downBlue
            }
            if abs( (blue ? -abs(point) : abs(point)) + downNotBlue) < diff {
                diff = abs( (blue ? -abs(point) : abs(point)) + downNotBlue)
                res = ((blue ? -abs(point) : abs(point)) + downNotBlue)
            }
        }
        
        if col+1 < mat[0].count {
            let rightBlue = dfs(row, col+1, true)
            let rightNotBlue = dfs(row, col+1, false)
            
            if abs((blue ? abs(point) : -abs(point)) + rightBlue) < diff {
                diff = abs((blue ? abs(point) : -abs(point)) + rightBlue)
                res = (blue ? abs(point) : -abs(point)) + rightBlue
            }
            if abs((blue ? -abs(point) : abs(point)) + rightNotBlue) < diff {
                diff = abs((blue ? -abs(point) : abs(point)) + rightNotBlue)
                res = (blue ? -abs(point) : abs(point)) + rightNotBlue
            }
        }
        
        dp[row][col][(blue ? 0 : 1)] = res
        return res
    }
}

print(Solution().balancedPath(mat))
