#include <bits/stdc++.h>
const int w = 3e5;
int b[w + 10];
int fw[w + 10];
std::vector<int> e[w + 10];
int query(int i) {
  ++i;
  if (i < 1) return 0;
  int res = 0;
  while (i >= 1) {
    res += fw[i];
    i -= i & -i;
  }
  return res;
}
void modify(int i, int v) {
  ++i;
  while (i <= w) {
    fw[i] += v;
    i += i & -i;
  }
}
int main() {
  int n, p;
  scanf("%d %d", &n, &p);
  int x, y;
  for (int i = 1; i <= n; ++i) {
    scanf("%d %d", &x, &y);
    if (x < y) std::swap(x, y);
    ++b[x];
    ++b[y];
    e[x].push_back(y);
  }
  for (int i = 1; i <= n; ++i) std::sort(e[i].begin(), e[i].end());
  long long ans = 0;
  for (int i = 1; i <= n; ++i) {
    int x = p - b[i];
    int sz = int(e[i].size());
    for (int j = 0; j < sz;) {
      int k = j + 1;
      while (k < sz && e[i][k] == e[i][j]) ++k;
      if (b[e[i][j]] >= x && b[e[i][j]] - (k - j) < x) --ans;
      j = k;
    }
    ans += query(w) - query(x - 1);
    modify(b[i], 1);
  }
  printf("%I64d", ans);
}
