#include <bits/stdc++.h>
using namespace std;
int n, p, deg[300001], ft[300001];
map<pair<int, int>, int> mp;
long long ans;
void upd(int i, int v) {
  i++;
  while (i > 0) ft[i] += v, i -= i & -i;
}
int get(int i) {
  i++;
  assert(i > 0);
  int ret = 0;
  while (i <= n) ret += ft[i], i += i & -i;
  return ret;
}
int main() {
  scanf("%d%d", &n, &p);
  for (int i = 1, x, y; i <= n; i++) {
    scanf("%d%d", &x, &y);
    deg[x]++;
    deg[y]++;
    mp[{min(x, y), max(x, y)}]++;
  }
  for (int i = 1; i <= n; i++) upd(deg[i], 1);
  for (int i = 1; i <= n; i++) {
    upd(deg[i], -1);
    vector<int> tmp;
    while (!mp.empty() and mp.begin()->first.first == i) {
      if (deg[i] + deg[mp.begin()->first.second] - mp.begin()->second >= p)
        ans++;
      upd(deg[mp.begin()->first.second], -1);
      tmp.push_back(deg[mp.begin()->first.second]);
      mp.erase(mp.begin());
    }
    ans += get(max(p - deg[i], 0));
    for (int d : tmp) upd(d, 1);
  }
  printf("%lld", ans);
}
