#include <bits/stdc++.h>
using namespace std;
int n, p, s[300010], x[300010], y[300010];
int a[300010];
map<pair<int, int>, int> sum;
int main() {
  scanf("%d%d", &n, &p);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &x[i], &y[i]);
    s[x[i]]++, s[y[i]]++;
  }
  for (int i = 1; i <= n; i++) a[i] = s[i];
  sort(s + 1, s + n + 1);
  long long ans = 0;
  int r = n + 1;
  for (int i = 1; i <= n; i++) {
    while (r > 1 && s[i] + s[r - 1] >= p) r--;
    ans += n - r + 1;
    ans -= (s[i] * 2 >= p);
  }
  ans /= 2;
  for (int i = 1; i <= n; i++) {
    if (x[i] > y[i]) swap(x[i], y[i]);
    sum[make_pair(x[i], y[i])]++;
  }
  for (int i = 1; i <= n; i++)
    if (sum[make_pair(x[i], y[i])])
      ans -= a[x[i]] + a[y[i]] >= p &&
             a[x[i]] + a[y[i]] - sum[make_pair(x[i], y[i])] < p,
          sum[make_pair(x[i], y[i])] = 0;
  return printf("%lld", ans), 0;
}
