#include <bits/stdc++.h>
using namespace std;
map<pair<int, int>, int> mapka;
int cnt[300001];
int n, p;
long long res;
int bs(int x) {
  int l = x + 1;
  int r = n;
  int res = n + 1;
  while (l <= r) {
    int m = l + r;
    m >>= 1;
    if (cnt[x] + cnt[m] >= p)
      res = m, r = m - 1;
    else
      l = m + 1;
  }
  return n - res + 1;
}
int main() {
  scanf("%d %d", &n, &p);
  for (int i = 0, x, y; i < n; ++i) {
    scanf("%d %d", &x, &y);
    ++cnt[x];
    ++cnt[y];
    if (x > y) swap(x, y);
    ++mapka[make_pair(x, y)];
  }
  for (map<pair<int, int>, int>::iterator it = mapka.begin(); it != mapka.end();
       ++it)
    res -= (cnt[it->first.first] + cnt[it->first.second] >= p &&
            cnt[it->first.first] + cnt[it->first.second] - it->second < p);
  sort(cnt + 1, cnt + n + 1);
  for (int i = 1; i < n; ++i) res += bs(i);
  cout << res << endl;
  return 0;
}
