#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
template <class T>
using pqg = priority_queue<T, vector<T>, greater<T>>;
int n, p;
map<int, int> wth[300001];
int num[300001];
const int mxN = 300000;
int bit[mxN + 5];
void upd(int i, int val) {
  i++;
  while (i < mxN + 5) {
    bit[i] += val;
    i += i & -i;
  }
}
int query(int i) {
  int ret = 0;
  i++;
  while (i > 0) {
    ret += bit[i];
    i -= i & -i;
  }
  return ret;
}
int rquery(int l, int r) { return query(r) - query(l - 1); }
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> p;
  for (int i = 1; i <= n; i++) {
    int x, y;
    cin >> x >> y;
    if (y < x) swap(x, y);
    wth[x][y]++;
    num[x]++;
    num[y]++;
  }
  long long ans = 0;
  upd(num[n], 1);
  for (int i = n - 1; i >= 1; i--) {
    int cnt = rquery(p - num[i], n);
    for (auto& k : wth[i]) {
      if (num[k.first] + num[i] >= p && num[k.first] + num[i] - k.second < p)
        cnt--;
    }
    ans += cnt;
    upd(num[i], 1);
  }
  cout << ans;
}
