import sys from collections import defaultdict sys.setrecursionlimit(10 ** 7) input = sys.stdin.readline f_inf = float('inf') mod = 10 ** 9 + 7 def resolve(): n, m = map(int, input().split()) cnt_col = [0] * n box = [defaultdict(int) for _ in range(m)] for _ in range(n): b, c = map(lambda x: int(x) - 1, input().split()) cnt_col[c] += 1 box[b][c] += 1 cnt_max = [0] * n for i in range(m): for k, v in box[i].items(): cnt_max[k] = max(cnt_max[k], v) res = sum(cnt_col[i] - cnt_max[i] for i in range(n)) print(res) if __name__ == '__main__': resolve()