#include <bits/stdc++.h>
using namespace std;
const long long N = 301101;
long long n, p, d[N], w, ans, x[N], y[N];
pair<long long, long long> k;
vector<long long> a;
map<pair<long long, long long>, long long> te;
int main() {
  scanf("%lld%lld", &n, &p);
  for (long long i = 1; i <= n; i++) {
    scanf("%lld%lld", &x[i], &y[i]);
    if (x[i] < y[i]) swap(x[i], y[i]);
    k.first = x[i], k.second = y[i];
    te[k]++;
    d[k.first]++, d[k.second]++;
  }
  for (long long i = 1; i <= n; i++) {
    if (d[i] >= p)
      w++;
    else
      a.push_back(d[i]);
  }
  ans = ((w * (w - 1)) / 2) + (w * a.size());
  if (!a.size()) return cout << ans, 0;
  sort(a.begin(), a.end());
  for (long long i = 0; i < a.size() - 1; i++) {
    long long l = i, r = a.size() - 1;
    if (a[l] + a[a.size() - 1] < p) continue;
    while (l + 1 < r) {
      long long mid = (l + r) / 2;
      if (a[mid] + a[i] >= p)
        r = mid;
      else
        l = mid;
    }
    ans += a.size() - r;
  }
  for (long long i = 1; i <= n; i++) {
    k.first = x[i], k.second = y[i];
    if (d[x[i]] + d[y[i]] >= p and d[x[i]] + d[y[i]] - te[k] < p and
        d[x[i]] < p and d[y[i]] < p) {
      ans--;
      te[k] = 0;
    }
  }
  cout << ans;
}
