#include <bits/stdc++.h>
using namespace std;
inline long long Rd() {
  long long x = 0;
  int ch = getchar(), f = 1;
  while (!isdigit(ch) && (ch != '-') && (ch != EOF)) ch = getchar();
  if (ch == '-') {
    f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 1) + (x << 3) + ch - '0';
    ch = getchar();
  }
  return x * f;
}
inline void Wr(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x >= 10)
    Wr(x / 10), putchar(x % 10 + '0');
  else
    putchar(x + '0');
}
const int N = 300005;
struct Doubt {
  int x, y;
  bool operator<(const Doubt& w) const { return x == w.x ? y < w.y : x < w.x; }
} a[N];
int n, p, Ex[N], Ct[N];
int main() {
  n = Rd(), p = Rd();
  for (int i = 1; i <= (int)n; i++) {
    a[i].x = Rd(), a[i].y = Rd();
    if (a[i].x > a[i].y) swap(a[i].x, a[i].y);
    Ex[a[i].x]++, Ex[a[i].y]++;
  }
  memcpy(Ct, Ex, sizeof Ex);
  sort(Ct + 1, Ct + n + 1);
  sort(a + 1, a + n + 1);
  long long Ans = 0;
  int Hd = 1, Ta = n;
  for (int i = 1; i <= (int)n; i++) {
    while (Ta > i && Ct[i] + Ct[Ta] >= p) Ta--;
    if (Ta == i) {
      Ans += 1ll * (n - i + 1) * (n - i) / 2;
      break;
    } else
      Ans += n - Ta;
  }
  while (Hd <= n) {
    int Ta = Hd;
    while (Ta < n && a[Ta + 1].x == a[Hd].x && a[Ta + 1].y == a[Hd].y) Ta++;
    int x = a[Hd].x, y = a[Hd].y;
    if (Ex[x] + Ex[y] >= p && Ex[x] + Ex[y] - (Ta - Hd + 1) < p) Ans--;
    Hd = Ta + 1;
  }
  Wr(Ans);
}
