h,w = gets.split.map(&:to_i)
a,b = 2.times.map{(1..h).map{gets.split.map(&:to_i)}}
ab = a.zip(b).map{|ta,tb|ta.zip(tb).map{|ua,ub|(ua-ub).abs}}

max = ab.map(&:max).max
zero = 1 << (h+w)*max/2

dp = [zero]
predp = [0]*w

ab.each{|abi|
  w.times{|tw|
    d = abi[tw]
    s = predp[tw] | dp[tw-1]
    dp[tw] = (s << d) | (s >> d)
  }
  predp,dp = dp,predp.clear.push(0)
}
ans = predp[-1]
p (0..max).find{|i|ans & ((zero << i)|(zero >> i)) > 0}