#include <bits/stdc++.h>
using namespace std;
const int maxn = 300000, hs = maxn;
int n, cnt[maxn + 1], a, b, p, t = 0, ct[maxn + 1], s[maxn + 1], maxi[maxn + 1],
                               j, pp[maxn + 1], pos;
long long tt = 0;
vector<pair<int, int> > bs;
struct Hash {
  int head[hs + 1], nex[maxn + 1], tt;
  pair<int, int> v[maxn + 1];
  void init() {
    memset(head, 0, sizeof(head));
    tt = 0;
  }
  int has(pair<int, int> va) {
    pair<int, int> ot;
    ot.first = va.second;
    ot.second = va.first;
    int h1 = (va.first + va.second) % hs;
    int h = head[h1];
    while (h) {
      if (v[h] == va || v[h] == ot) return h;
      h = nex[h];
    }
    tt++;
    v[tt] = va;
    nex[tt] = head[h1];
    head[h1] = tt;
    return tt;
  }
} h;
void reloc() {
  freopen("/Users/admin/Desktop/cards.in", "r", stdin);
  freopen("/Users/admin/Desktop/cards.out", "w", stdout);
  return;
}
bool cmp(int a, int b) { return cnt[a] < cnt[b]; }
long long CCnt(int j, int l) {
  long long ans;
  for (; cnt[s[pos]] + cnt[j] >= p && pos > 0; pos--)
    ;
  ans = n - pos;
  if (cnt[j] * 2 >= p) ans--;
  return ans;
}
int main() {
  h.init();
  memset(cnt, 0, sizeof(cnt));
  memset(ct, 0, sizeof(ct));
  memset(maxi, 0, sizeof(maxi));
  scanf("%d %d", &n, &p);
  pos = n;
  int ccc;
  for (int i = 1; i <= n; i++) {
    scanf("%d %d", &a, &b);
    cnt[a]++;
    cnt[b]++;
    ccc = ++ct[h.has(make_pair(a, b))];
    maxi[a] = max(maxi[a], ccc);
    maxi[b] = max(maxi[b], ccc);
  }
  for (int i = 1; i <= n; i++) s[i] = i;
  sort(s + 1, s + 1 + n, cmp);
  for (int i = 1; i <= n; i++) pp[s[i]] = i;
  for (int i = 1; i <= n; i++) {
    j = s[i];
    tt += CCnt(j, maxi[j]);
  }
  int x, y;
  for (int i = 1; i <= h.tt; i++) {
    x = h.v[i].first;
    y = h.v[i].second;
    if (cnt[x] + cnt[y] >= p && cnt[x] + cnt[y] - ct[i] < p) tt -= 2;
  }
  printf("%lld\n", tt / 2);
  return 0;
}
