#include <bits/stdc++.h>
using namespace std;
const long long inf = INT_MAX, df = 3e5 + 7;
struct node {
  long long fir, sec;
} f[df];
long long i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a[df], cnt[df],
    ans;
inline long long read() {
  long long x = 0, y = 1;
  char ch = getchar();
  while (ch > '9' || ch < '0') y = (ch == '-') ? -1 : 1, ch = getchar();
  while (ch >= '0' && ch <= '9')
    x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
  return x * y;
}
bool cmp(node st, node ch) {
  return (st.fir == ch.fir) ? st.sec < ch.sec : st.fir < ch.fir;
}
int main() {
  n = read(), p = read();
  for (long long i = (1); i <= (n); ++i) {
    f[i].fir = read(), f[i].sec = read();
    if (f[i].fir > f[i].sec) swap(f[i].fir, f[i].sec);
    cnt[f[i].fir]++, cnt[f[i].sec]++;
  }
  for (long long i = (1); i <= (n); ++i) a[i] = cnt[i];
  sort(cnt + 1, cnt + n + 1);
  for (long long i = (n); i >= (1); --i) {
    if (cnt[i] >= p)
      ans += n - 1;
    else {
      long long ty = (lower_bound(cnt + 1, cnt + n + 1, p - cnt[i]) - cnt);
      ans += n - ty + 1;
      if (i >= ty) ans--;
    }
  }
  ans >>= 1;
  sort(f + 1, f + n + 1, cmp);
  node tmp;
  tmp.fir = tmp.sec = 0;
  long long ty = 0;
  for (long long i = (1); i <= (n); ++i) {
    if (tmp.fir == f[i].fir && tmp.sec == f[i].sec)
      ty++;
    else {
      if (tmp.fir && a[tmp.fir] + a[tmp.sec] >= p &&
          a[tmp.fir] + a[tmp.sec] - ty < p)
        --ans;
      ty = 1;
      tmp.fir = f[i].fir, tmp.sec = f[i].sec;
    }
  }
  if (a[tmp.fir] + a[tmp.sec] >= p && a[tmp.fir] + a[tmp.sec] - ty < p) --ans;
  printf("%lld\n", ans);
}
