#include <bits/stdc++.h>
using namespace std;
long long ans;
int n, p, pre, sl[300069], tmp[300069];
pair<int, int> x[300069];
int main() {
  scanf("%d%d", &n, &p);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &x[i].first, &x[i].second);
    if (x[i].first > x[i].second) swap(x[i].first, x[i].second);
    sl[x[i].first]++;
    sl[x[i].second]++;
    tmp[x[i].first]++;
    tmp[x[i].second]++;
  }
  sort(tmp + 1, tmp + 1 + n);
  pre = 1;
  for (int i = n; i > pre; --i) {
    while (tmp[pre] + tmp[i] < p && pre < i) pre++;
    ans += i - pre;
  }
  sort(x + 1, x + 1 + n);
  for (int fr, i = 1; i <= n; i = fr) {
    fr = i + 1;
    while (fr <= n && x[i] == x[fr]) fr++;
    if (sl[x[i].first] + sl[x[i].second] >= p &&
        sl[x[i].first] + sl[x[i].second] - (fr - i) < p)
      ans--;
  }
  cout << ans;
}
