import java.util.Scanner; class Main { public static void main(String arg[]) { Scanner cin = new Scanner(System.in); int N = cin.nextInt(); int M = cin.nextInt(); int[][] R = new int[N][M]; int[] last = new int[M]; int[] deg = new int[N]; int ans = 0; for(int i = 0; i < N; i++) { for(int j = 0; j < M; j++) { R[i][j] = cin.nextInt(); if(R[i][j] > R[last[j]][j]) { for(int k = last[j]; k < i; k++) { if(R[last[j]][j] == R[k][j]) { deg[k]--; if(deg[k] == 0) { ans--; } } } last[j] = i; deg[i]++; if(deg[i] == 1) ans++; } else if(R[i][j] == R[last[j]][j]) { deg[i]++; if(deg[i] == 1) ans++; } } System.out.println(ans); } } }