program balanced_path
  implicit none
  integer :: h, w, i, j, a(80,80) = 0, b(80) = 0, x = 1000000000
  read(*,*) h, w
  do i = 1, h
    read(*,*) a(i,1:w)
  end do
  do i = 1, h
    read(*,*) b(1:w)
    a(i,1:w) = a(i,1:w)-b(1:w)
  end do
  call dfs(1,1,a(1,1))
  write(*,'(i0)') x
contains
  recursive subroutine dfs(i,j,d)
    integer, intent(in) :: i, j, d
    if (i == h .and. j == w) then
      x = min(x,abs(d))
      return
    end if
    if (i < h) then
      call dfs(i+1,j,d+a(i+1,j))
      call dfs(i+1,j,d-a(i+1,j))
    end if
    if (j < w) then
      call dfs(i,j+1,d+a(i,j+1))
      call dfs(i,j+1,d-a(i,j+1))
    end if
  end
end program balanced_path