#include <bits/stdc++.h>
using namespace std;
long long solve(int n, int p, vector<int>& v, vector<int>& who) {
  vector<pair<int, int> > w(n);
  for (int i = 0; i < n; i++) {
    w[i] = {who[i], v[i]};
  }
  sort(w.begin(), w.end());
  long long ret = 0;
  for (int i = 0, k = n; i < n - 1; i++) {
    while (k > i && w[k - 1].first + w[i].first >= p) {
      k--;
    }
    k = max(k, i + 1);
    if (k == n) continue;
    ret += n - k;
  }
  return ret;
}
int main() {
  ios::sync_with_stdio(false);
  int n, p;
  long long x, y;
  cin >> n >> p;
  vector<int> who(n, 0);
  vector<int> v(n);
  map<long long, int> m;
  for (int i = 0; i < n; i++) {
    cin >> x >> y;
    if (x > y) swap(x, y);
    x--, y--;
    long long s = x | y << 30LL;
    m[s]++;
    who[x]++;
    who[y]++;
    v[i] = i;
  }
  long long ret = solve(n, p, v, who);
  for (auto& x : m) {
    pair<int, int> a = {x.first & ((1 << 30) - 1), x.first >> 30LL};
    int num = x.second;
    if (who[a.first] + who[a.second] >= p &&
        who[a.first] + who[a.second] - num < p) {
      ret--;
    }
  }
  cout << ret;
  return 0;
}
