from collections import defaultdict, Counter dic = defaultdict(list) N, M = map(int, input().split()) BC = [list(map(int, input().split())) for _ in range(N)] for b, c in BC: dic[c].append(b) ans = 0 for k, v in dic.items(): n = len(v) L = list(Counter(v).items()) L.sort(key = lambda x:-x[1]) ans += n - L[0][1] print(ans)