import sys sys.setrecursionlimit(100000000) MOD = 17 INF = 10 ** 15 def main(): N,M = map(int,input().split()) param = [tuple(map(int,input().split())) for _ in range(N)] before = [set() for _ in range(M)] before_max = [0] * M ans = 0 for i in range(N): exceed = False for j in range(M): if before_max[j] < param[i][j]: before_max[j] = param[i][j] exceed = True for s in before[j]: flag = False for k in range(M): if k == j: continue if s in before[k]: flag = True break if not flag: ans -= 1 before[j].clear() before[j].add(i) elif before_max[j] == param[i][j]: before[j].add(i) exceed = True if exceed: ans += 1 print(ans) if __name__ == '__main__': main()