#include <bits/stdc++.h>
using namespace std;
int n, p;
int a[300005], b[300005], cnt[300005], pos[300005];
vector<int> v[300005];
int temp[300005];
vector<pair<int, int> > order;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> p;
  for (int i = 1; i <= n; i++) {
    cin >> a[i] >> b[i];
    cnt[a[i]]++;
    cnt[b[i]]++;
    v[a[i]].push_back(i);
    v[b[i]].push_back(i);
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    order.push_back(make_pair(cnt[i], i));
  }
  sort(order.begin(), order.end());
  for (int i = 0; i < order.size(); i++) {
    int id = order[i].second;
    pos[id] = i;
  }
  for (int i = 0; i < order.size() - 1; i++) {
    int req = p - order[i].first;
    int low = i + 1, high = n - 1;
    while (low < high) {
      int mid = low + (high - low) / 2;
      if (order[mid].first >= req)
        high = mid;
      else
        low = mid + 1;
    }
    if (order[low].first < req) low++;
    long long tot = n - low;
    vector<int> buff;
    long long cnt = 0;
    for (int j = 0; j < v[order[i].second].size(); j++) {
      int support = v[order[i].second][j];
      if (pos[a[support]] >= low) {
        if (temp[pos[a[support]]] == 0) {
          buff.push_back(pos[a[support]]);
        }
        temp[pos[a[support]]]++;
      }
      if (pos[b[support]] >= low) {
        if (temp[pos[b[support]]] == 0) {
          buff.push_back(pos[b[support]]);
        }
        temp[pos[b[support]]]++;
      }
    }
    for (auto it = buff.begin(); it != buff.end(); it++) {
      int pos = *(it);
      if (order[pos].first - temp[pos] < req) tot--;
      temp[pos] = 0;
    }
    ans += tot;
    buff.clear();
  }
  cout << ans << "\n";
}
