#include <bits/stdc++.h>
using namespace std;
int n, need;
int a[300000], b[300000];
int deg[300000];
int fst[300000];
int nxt[300000];
int to[600000];
int cnt[600000];
int sorted[300000];
int rev[300000];
bool degcmp(int a, int b) { return deg[a] < deg[b]; }
void run() {
  scanf("%d%d", &n, &need);
  for (int i = (0); i < (n); ++i) {
    scanf("%d%d", &a[i], &b[i]);
    --a[i];
    --b[i];
  }
  memset(deg, 0, sizeof(deg));
  for (int i = (0); i < (n); ++i) {
    ++deg[a[i]];
    ++deg[b[i]];
  }
  fst[0] = nxt[0] = 0;
  for (int i = (1); i < (n); ++i) fst[i] = nxt[i] = fst[i - 1] + deg[i - 1];
  for (int i = (0); i < (n); ++i) {
    int idx1 = nxt[a[i]]++;
    to[idx1] = b[i];
    int idx2 = nxt[b[i]]++;
    to[idx2] = a[i];
  }
  for (int i = (0); i < (n); ++i) sort(to + fst[i], to + nxt[i]);
  for (int i = (0); i < (n); ++i) {
    int nnxt = fst[i];
    for (int j = (fst[i]); j < (nxt[i]); ++j)
      if (nnxt != fst[i] && to[j] == to[nnxt - 1])
        ++cnt[nnxt - 1];
      else {
        to[nnxt] = to[j];
        cnt[nnxt] = 1;
        ++nnxt;
      }
    nxt[i] = nnxt;
  }
  for (int i = (0); i < (n); ++i) sorted[i] = i;
  sort(sorted, sorted + n, degcmp);
  for (int i = (0); i < (n); ++i) rev[sorted[i]] = i;
  int ai = 0, bi = n - 1;
  long long ret = 0;
  while (ai < bi) {
    int a = sorted[ai], b = sorted[bi];
    if (deg[a] + deg[b] < need) {
      ++ai;
      continue;
    }
    int now = bi - ai;
    for (int j = (fst[b]); j < (nxt[b]); ++j) {
      if (ai <= rev[to[j]] && rev[to[j]] < bi &&
          deg[to[j]] + deg[b] - cnt[j] < need)
        --now;
    }
    ret += now;
    --bi;
  }
  cout << ret << endl;
}
int main() {
  run();
  return 0;
}
