#include <bits/stdc++.h>
using namespace std;
int cnt[300010];
int freq[300010];
void inc(int k) {
  cnt[k]++;
  freq[cnt[k]]++;
}
void dec(int k) {
  freq[cnt[k]]--;
  cnt[k]--;
}
void clear(int k) {
  while (cnt[k] >= 0) {
    freq[cnt[k]]--;
    --cnt[k];
  }
}
pair<int, int> p[300010];
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  freq[0] = n;
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &p[i].first, &p[i].second);
    if (p[i].first > p[i].second) {
      swap(p[i].first, p[i].second);
    }
    inc(p[i].first);
    inc(p[i].second);
  }
  sort(p, p + n);
  int st = 0, nd = 0, t;
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    while (nd < n && p[nd].first == i) {
      ++nd;
    }
    for (int t = st; t < nd; t++) {
      dec(p[t].first);
      dec(p[t].second);
    }
    int r = k - (nd - st) - cnt[i];
    clear(i);
    ans += freq[max(r, 0)];
    for (int t = st; t < nd; t++) {
      inc(p[t].second);
    }
    st = nd;
  }
  printf("%I64d\n", ans);
  return 0;
}
