n, m = map(int, input().split()) R = [[]] * n last = [0] * m deg = [0] * n ans = 0 for i in range(n): R[i] = [int(v) for v in input().split()] for j in range(m): if R[i][j] > R[last[j]][j]: for k in range(last[j], i): if R[last[j]][j] == R[k][j]: deg[k] -= 1 if deg[k] == 0: ans -= 1 last[j] = i deg[i] += 1 if deg[i] == 1: ans += 1 elif R[i][j] == R[last[j]][j]: deg[i] += 1 if deg[i] == 1: ans += 1 print(ans)