def main(): import sys input = sys.stdin.read data = input().split() idx = 0 N = int(data[idx]) M = int(data[idx + 1]) idx += 2 R = [] for _ in range(N): R.append(list(map(int, data[idx:idx + M]))) idx += M current_max_val = [0] * M current_max_people = [set() for _ in range(M)] active = [0] * (N + 2) # 1-based indexing result = 0 answers = [] for k in range(1, N + 1): row = R[k-1] for j in range(M): val = row[j] if val > current_max_val[j]: # Process previous max people prev_people = current_max_people[j] for i in prev_people: old = active[i] active[i] -= 1 new = active[i] if old == 1 and new == 0: result -= 1 current_max_people[j].clear() current_max_val[j] = val current_max_people[j].add(k) # Now add k old = active[k] active[k] += 1 new = active[k] if old == 0 and new == 1: result += 1 elif val == current_max_val[j]: if k not in current_max_people[j]: current_max_people[j].add(k) old = active[k] active[k] += 1 new = active[k] if old == 0 and new == 1: result += 1 answers.append(result) for ans in answers: print(ans) if __name__ == '__main__': main()