#include <bits/stdc++.h>
const long long MAX_N = 3e5 + 100;
using namespace std;
map<pair<int, int>, long long> mp;
long long d[MAX_N];
int main() {
  int n, p;
  cin >> n >> p;
  for (int i = 1; i <= n; ++i) {
    long long x, y;
    scanf("%lld%lld", &x, &y);
    if (x > y) swap(x, y);
    d[x]++;
    d[y]++;
    mp[{x, y}]++;
  }
  vector<long long> v;
  for (long long i = 1; i <= n; ++i) v.push_back(d[i]);
  long long ans = 0;
  sort(v.begin(), v.end());
  for (long long i = n - 1; i > 0; --i) {
    if (v[i] + v[i - 1] < p) break;
    if (v[i] + v[0] >= p) {
      ans += i;
      continue;
    }
    long long r = i - 1;
    long long l = 0;
    while (r - l > 1) {
      long long mid = (l + r) / 2;
      if (v[mid] + v[i] >= p)
        r = mid;
      else
        l = mid;
    }
    ans += i - r;
  }
  for (auto x : mp) {
    long long a = x.first.first;
    long long b = x.first.second;
    if (d[a] + d[b] >= p and d[a] + d[b] - x.second < p) ans--;
  }
  cout << ans;
  return 0;
}
