import Data.Array
import Control.Monad

main = do
    [h, w] <- map read <$> words <$> getLine
    a <- listArray (1, h) <$> (forM [1 .. h] $ \_ -> listArray (1, w) <$> map read <$> words <$> getLine)
    b <- listArray (1, h) <$> (forM [1 .. h] $ \_ -> listArray (1, w) <$> map read <$> words <$> getLine)
    putStrLn $ show $ solve h w a b

solve :: Int -> Int -> Array Int (Array Int Int) -> Array Int (Array Int Int) -> Int
solve h w a b = minimum $ filter (\v -> dp ! (h, w, v)) $ [0 .. maxv]
  where
    dp = listArray ((1, 1, 0), (h, w, maxv)) [doit y x v | y <- [1 .. h], x <- [1 .. w], v <- [0 .. maxv]]
    doit 1 1 v = v == abs (a ! 1 ! 1 - b ! 1 ! 1)
    doit y x v = ((x > 1 && v1 >= 0 && v1 <= maxv && dp ! (y, x - 1, v1)) ||
                  (x > 1 && v2 >= 0 && v2 <= maxv && dp ! (y, x - 1, v2)) ||
                  (y > 1 && v1 >= 0 && v1 <= maxv && dp ! (y - 1, x, v1)) ||
                  (y > 1 && v2 >= 0 && v2 <= maxv && dp ! (y - 1, x, v2)))
      where
        v1 = abs (v - a ! y ! x + b ! y ! x)
        v2 = abs (v + a ! y ! x - b ! y ! x)
    maxv = 80 * 80
