class Bit: def __init__(self, n): self.size = n self.tree = [0] * (n + 1) def sum(self, i): s = 0 while i > 0: s += self.tree[i] i -= i & -i return s def add(self, i, x): while i <= self.size: self.tree[i] += x i += i & -i n,m = map(int,input().split()) ab = [0]*n for i in range(n): a,b = map(int,input().split()) if a < b: ab[i] = [b,a] else: ab[i] = [a,b] ab.sort(reverse=True) #print(ab) ans = 0 bit = Bit(m+1) for i in range(n): bit.add(ab[i][1]+1,1) ans += (bit.sum(ab[i][0]+1)-bit.sum(ab[i][1]+1)) print(ans)