#include <bits/stdc++.h>
using namespace std;
vector<int> cnt;
vector<pair<int, int> > a;
int n, p;
vector<int> tree;
void up(int i, int v) {
  ++i;
  for (; i < tree.size(); i += (i & (-i))) tree[i] += v;
}
int get(int i) {
  ++i;
  int v = 0;
  for (; i; i -= (i & (-i))) v += tree[i];
  return v;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> p;
  cnt.assign(n + 1, 0);
  ;
  a.assign(n, pair<int, int>());
  ;
  for (int i = 0; i < (int)n; ++i) {
    cin >> a[i].first >> a[i].second;
    if (a[i].first < a[i].second) swap(a[i].first, a[i].second);
    ++cnt[a[i].first];
    if (a[i].second != a[i].first) ++cnt[a[i].second];
  }
  sort(a.begin(), a.end());
  tree.assign(n + 2, 0);
  ;
  long long ans = 0;
  int cur = 0;
  for (int i = 1; i < (int)n + 1; ++i) {
    int hi = cur;
    while (hi < n && a[hi].first == i) {
      if (a[hi].first != a[hi].second)
        --cnt[a[hi].second], up(cnt[a[hi].second] + 1, -1),
            up(cnt[a[hi].second], 1);
      ++hi;
    }
    ans += get(n) - get(max(-1, p - cnt[i] - 1));
    while (cur < hi) {
      if (a[cur].first != a[cur].second)
        ++cnt[a[cur].second], up(cnt[a[cur].second] - 1, -1),
            up(cnt[a[cur].second], 1);
      ++cur;
    }
    up(cnt[i], 1);
  }
  cout << ans << endl;
}
