import java.io.FileNotFoundException; import java.io.PrintWriter; import java.util.Arrays; import java.util.PriorityQueue; import java.util.Scanner; public class Main { public static void main(String[] args) throws FileNotFoundException { new Main().run(); } void run() { Scanner sc = new Scanner(System.in); PrintWriter pw = new PrintWriter(System.out); int N = sc.nextInt(); int M = sc.nextInt(); int[][] R = new int[N][M]; PriorityQueue[] pqs = new PriorityQueue[M]; for (int i = 0; i < pqs.length; ++i) { pqs[i] = new PriorityQueue<>(); } int[] curVal = new int[M]; int[] vanish = new int[N]; int ans = 0; for (int i = 0; i < N; ++i) { for (int j = 0; j < M; ++j) { R[i][j] = sc.nextInt(); } } for (int i = 0; i < N; ++i) { for (int j = 0; j < M; ++j) { curVal[j] = Math.max(curVal[j], R[i][j]); pqs[j].add((long) R[i][j] << 32 | i); } ++ans; for (int j = 0; j < M; ++j) { while (!pqs[j].isEmpty() && (pqs[j].peek() >> 32) < curVal[j]) { int idx = pqs[j].poll().intValue(); ++vanish[idx]; if (vanish[idx] == M) { --ans; } } } pw.println(ans); } pw.close(); } static void tr(Object... objects) { System.out.println(Arrays.deepToString(objects)); } }