import sys, math sys.setrecursionlimit(10**8) sys.set_int_max_str_digits(0) INF = 10**18 MOD = 998244353 from bisect import bisect_left, bisect_right from collections import deque, defaultdict, Counter from itertools import product, combinations, permutations, groupby, accumulate from heapq import heapify, heappop, heappush N, M = map(int, input().split()) data = defaultdict(list) for i in range(N): b, c = map(int, input().split()) data[c].append(b) ans = 0 for k, v in data.items(): most_common_box_for_this_color = Counter(v).most_common()[0][1] #print(k, most_common_box_for_this_color) ans += len(v) - most_common_box_for_this_color print(ans)