#include <bits/stdc++.h>
using namespace std;
map<pair<int, int>, int> pb;
const int maxn = 300500;
unsigned long long cnt[maxn];
unsigned long long ans, n, p;
int main() {
  scanf("%llu%llu", &n, &p);
  for (int i = 1; i <= n; i++) {
    unsigned long long u, v;
    scanf("%llu%llu", &u, &v);
    cnt[u]++;
    cnt[v]++;
    if (u > v) swap(v, u);
    pb[make_pair(u, v)]++;
  }
  for (map<pair<int, int>, int>::iterator it = pb.begin(), d = pb.end();
       it != d; it++) {
    int s1 = ((*it).first).first;
    int s2 = ((*it).first).second;
    int res = cnt[s1] + cnt[s2];
    if (res >= p && res - (*it).second < p) ans--;
  }
  sort(cnt + 1, cnt + n + 1);
  int top = n;
  for (int i = 1; i <= n; i++) {
    top = max(i, top);
    while (i < top && cnt[i] + cnt[top] >= p) top--;
    ans += n - top;
  }
  printf("%llu\n", ans);
  return 0;
}
