#include <bits/stdc++.h>
using namespace std;
int n, P, d[600005], l[600005], qd[600005], qn[600005], E, x, y, b[600005],
    pos[600005];
struct data {
  int x, c;
  bool operator<(const data& T) const { return c < T.c; }
} C[600005];
long long ret;
map<int, int> M[600005];
void bd(int x, int y) {
  qd[++E] = y;
  qn[E] = l[x];
  l[x] = E;
}
int main() {
  scanf("%d%d", &n, &P);
  memset(l, 0, sizeof(l));
  E = 0;
  memset(d, 0, sizeof(d));
  memset(b, 0, sizeof(b));
  for (int i = (0); i < (600005); i++) M[i].clear();
  for (int i = (0); i < (n); i++) {
    scanf("%d%d", &x, &y);
    d[x]++;
    d[y]++;
    if (M[x][y] == 0) {
      bd(x, y);
      bd(y, x);
    }
    M[x][y]++;
    M[y][x]++;
  }
  for (int i = (0); i < (n); i++) C[i].x = i + 1, C[i].c = d[i + 1];
  sort(C, C + n);
  for (int i = (0); i < (n); i++) pos[C[i].x] = i;
  int p = n - 1;
  ret = 0;
  for (int i = (0); i < (n); i++) {
    while (p > i && C[i].c + C[p].c >= P) p--;
    p = max(p, i);
    ret += n - p - 1;
    b[C[i].x] = 1;
    for (int k = l[C[i].x]; k; k = qn[k])
      if (d[qd[k]] + C[i].c - M[C[i].x][qd[k]] < P && pos[qd[k]] > p) ret--;
  }
  printf("%I64d\n", ret);
  return 0;
}
