module S = Set.Make (struct type t = int let compare = compare end)

let () =
    let main () =
        let h, w = Scanf.scanf "%d %d" (fun h w -> h, w) in
        let a = Array.init h (fun _ -> Array.init w (fun _ -> Scanf.scanf " %d" (fun n -> n))) in
        let b = Array.init h (fun _ -> Array.init w (fun _ -> Scanf.scanf " %d" (fun n -> n))) in
        let ar = Array.make_matrix (h + 1) (w + 1) (S.singleton 0) in
        let merge s1 s2 v1 v2 =
            let s = S.fold (fun v acc -> S.add (v + v2 - v1) (S.add (v + v1 - v2) acc)) s1 S.empty in
                    S.fold (fun v acc -> S.add (v + v2 - v1) (S.add (v + v1 - v2) acc)) s2 s
        in
        for y = 1 to h do
            for x = 1 to w do
                ar.(y).(x) <- merge ar.(y - 1).(x) ar.(y).(x - 1) a.(y - 1).(x - 1) b.(y - 1).(x - 1)
            done
        done;
        let s = S.map abs ar.(h).(w) in
        Printf.printf "%d\n" (S.min_elt s)
    in
    main ()