#include <bits/stdc++.h>
using namespace std;
int n, p, x, y, sus[300005];
int num, E[300005 * 2], nxt[300005 * 2], head[300005];
void add(int x, int y) {
  E[num] = y;
  nxt[num] = head[x];
  head[x] = num++;
}
struct node {
  int id, rs;
  bool operator<(const node &T) const { return sus[rs] < sus[T.rs]; }
} coder[300005];
long long ans;
int main() {
  scanf("%d%d", &n, &p);
  num = 0;
  memset(head, -1, sizeof(head));
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &x, &y);
    x--;
    y--;
    sus[x]++;
    sus[y]++;
    add(x, y);
    add(y, x);
  }
  for (int i = 0; i < n; i++) coder[i].id = coder[i].rs = i;
  sort(coder, coder + n);
  int lier = n - 1;
  for (int i = 0; i < n; i++) {
    int tmp = coder[i].rs;
    while ((lier >= 0) && (sus[tmp] + sus[coder[lier].rs] >= p)) lier--;
    ans += min(n - i - 1, n - lier - 1);
    for (int j = head[tmp]; j != -1; j = nxt[j]) {
      int frd = E[j];
      if ((coder[frd].id > coder[tmp].id) && (sus[frd] + sus[tmp] == p)) ans--;
      sus[frd]--;
    }
    for (int j = head[tmp]; j != -1; j = nxt[j]) sus[E[j]]++;
  }
  printf("%I64d\n", ans);
  return 0;
}
