// https://atcoder.jp/contests/abc147/tasks/abc147_e
//
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };

    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, [ next / $t:tt ]) => {
        {
            let len = read_value!($iter, usize);
            (0..len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
        }
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! dvec {
    ($t:expr ; $len:expr) => {
        vec![$t; $len]
    };

    ($t:expr ; $len:expr, $($rest:expr),*) => {
        vec![dvec!($t; $($rest),*); $len]
    };
}

#[allow(unused_macros)]
macro_rules! ifv {
    ($t:expr, $a:expr, $b: expr) => {
        if $t { $a } else { $b }
    }
}

#[allow(unused_macros)]
macro_rules! fill {
    ($t:expr, $v:expr) => {
        for i in 0..$t.len() {
            $t[i] = $v;
        }
    };
}

#[allow(unused_macros)]
macro_rules! join {
    ($t:expr, $glue:expr) => {
        $t.into_iter().map(|w| w.to_string()).collect::<Vec<_>>().join($glue)
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

const GETA: usize = 12810;

fn main() {
    input! {
        h: usize, w: usize,
        a: [[i64; w]; h],
        b: [[i64; w]; h],
    };

    let mut table = vec![vec![0usize; w]; h];
    for i in 0..h {
        for j in 0..w {
            table[i][j] = (a[i][j] - b[i][j]).abs() as usize;
        }
    }

    let mut dp = dvec!(false; 2, h, GETA*2);
    dp[0][0][GETA-table[0][0]] = true;
    dp[0][0][GETA+table[0][0]] = true;
    for t in 0..h+w-2 {
        let fr = t % 2;
        let to = 1 - fr;
        for i in 0..h {
            fill!(dp[to][i], false);
        }
        for i in 0..t+1 {
            let j = t-i;
            if i >= h || j >= w {
                continue;
            }
            for g in 0..GETA*2 {
                if !dp[fr][i][g] {
                    continue;
                }
                if i+1 < h {
                    let l = table[i+1][j];
                    dp[to][i+1][g-l] = true;
                    dp[to][i+1][g+l] = true;
                }
                if j+1 < w {
                    let l = table[i][j+1];
                    dp[to][i][g-l] = true;
                    dp[to][i][g+l] = true;
                }
            }
        }
    }

    let mut best = GETA as i64;
    for i in 0..GETA*2 {
        if dp[(h+w)%2][h-1][i] {
            let diff = ((i as i64) - (GETA as i64)).abs();
            best = min(best, diff);
        }
    }
    println!("{}", best);
}


Measured memory_bytes: 8444