#include <bits/stdc++.h>
using namespace std;
typedef long long arrv[600000 + 10];
typedef long long arre[800000 + 10];
long long i, j, k, p, n, m, tot, ans;
arrv g, f, a;
arre pt, nt, w;
struct node {
  long long x, y;
} q[600000 + 10];
void Link(long long x, long long y) {
  pt[++tot] = y, nt[tot] = g[x], g[x] = tot, w[tot] = m + 1;
}
void Inc(long long x, long long p) {
  if (x <= 0) return;
  for (; x <= n; x += ((x) & (-x))) a[x] += p;
}
long long Sum(long long x) {
  if (x < 0) return -a[0];
  long long res = 0;
  for (; x; x -= ((x) & (-x))) res += a[x];
  return res;
}
bool cmp(node a, node b) {
  if (a.x != b.x) return a.x < b.x;
  return a.y < b.y;
}
void Init() {
  scanf(
      "%I64d"
      "%I64d"
      "\n",
      &n, &m);
  for (i = 1; i <= n; ++i) {
    scanf(
        "%I64d"
        "%I64d"
        "\n",
        &q[i].x, &q[i].y);
    if (q[i].x > q[i].y) q[i].x ^= q[i].y, q[i].y ^= q[i].x, q[i].x ^= q[i].y;
  }
  sort(q + 1, q + n + 1, cmp);
  for (i = 1; i <= n; ++i) {
    bool flag = 0;
    j = q[i].x, k = q[i].y;
    for (p = g[j]; p; p = nt[p])
      if (pt[p] == k + n) {
        w[p]++, flag = 1;
        break;
      }
    if (!flag) Link(j, k + n);
    ++f[j], ++f[k];
  }
  for (i = 1; i <= n; ++i)
    if (!f[i])
      a[0]++;
    else
      Inc(f[i], 1);
}
void Calc() {
  if (!m) {
    printf(
        "%I64d"
        "\n",
        n * (n - 1) / 2);
    return;
  }
  for (i = 1; i <= n; ++i)
    if (f[i]) {
      Inc(f[i], -1);
      for (j = g[i]; j; j = nt[j]) {
        if (f[i] + f[pt[j] - n] >= w[j]) ans++;
        Inc(f[pt[j] - n], -1);
      }
      ans += Sum(n) - Sum(m - f[i] - 1);
      for (j = g[i]; j; j = nt[j]) Inc(f[pt[j] - n], 1);
    }
  printf(
      "%I64d"
      "\n",
      ans);
}
int main() {
  Init();
  Calc();
  return 0;
}
