import java.util.*; public class Main{ private static int m,n,min = 100; private static int[][] g; public static void main(String args[]) { Scanner cin = new Scanner(System.in); m = cin.nextInt(); n = cin.nextInt(); int sum = 0; g = new int[n][m]; for(int i = 0; i < n; i++) { for(int j = 0; j < m; j++) { g[i][j] = cin.nextInt(); sum += g[i][j]; } } cal(0, 0, sum/2, 0, new int[n][m]); System.out.println(min); } private static Boolean cal(int nn, int mm, int s, int num, int[][] ed) { if(s == 0 ) { if(num < min) min = num; return true; } if(s < 0) return false; if(nn < n && mm < m && nn >= 0 && mm >= 0) { if(ed[nn][mm] == 0) { ed[nn][mm] = 1; s -= g[nn][mm]; num++; cal(nn-1, mm, s, num, ed); cal(nn+1, mm, s, num, ed); cal(nn, mm-1, s, num, ed); cal(nn, mm+1, s, num, ed); ed[nn][mm] = 0; } } return false; } }