#include <bits/stdc++.h>
using namespace std;
const int maxx = 600010;
const double pi = acos(-1.0);
const double eps = 1e-15;
map<pair<int, int>, int> h;
map<pair<int, int>, int>::iterator it;
int t, n, m, x, y, p;
int l = 0, r = 0;
int bj[maxx];
long long ans = 0, total = 0, sum = 0, cnt = 0;
struct node {
  int num;
  long long val;
} s[maxx];
bool cmp(node a, node b) { return a.val < b.val; }
int main() {
  scanf("%d%d", &n, &p);
  for (int i = 1; i <= n; i++) {
    s[i].num = i;
    scanf("%d%d", &x, &y);
    if (x > y) swap(x, y);
    s[x].val++, s[y].val++, h[make_pair(x, y)]++;
  }
  sort(s + 1, s + n + 1, cmp);
  for (int i = 1; i <= n; i++) bj[s[i].num] = i;
  for (int i = 1; i <= n; i++) {
    l = i + 1, r = n, sum = n + 1;
    while (l <= r) {
      int mid = (l + r) >> 1;
      if (s[i].val + s[mid].val >= p)
        sum = mid, r = mid - 1;
      else
        l = mid + 1;
    }
    ans += n - sum + 1;
  }
  for (it = h.begin(); it != h.end(); it++) {
    x = it->first.first, y = it->first.second;
    if (s[bj[x]].val + s[bj[y]].val >= p &&
        s[bj[x]].val + s[bj[y]].val - it->second < p)
      ans--;
  }
  printf("%lld", ans);
  return 0;
}
