n = list(map(int, input().split())) xy = [map(int, input().split()) for _ in range(n[0])] x, y = [list(i) for i in zip(*xy)] l = [] for i in range(1,n[0]+1): m = y.count(i) if m != 0: L = [] for j in range(m): d = y.index(i) X = x.pop(d) Y = y.pop(d) L.append(X) LL = set(L) ANS = len(LL)-1 l.append(ANS) else: pass ans = sum(l) print(ans)