#include <bits/stdc++.h>
using namespace std;
struct CNode {
  int x, y;
};
bool operator<(const CNode &a, const CNode &b) {
  return (a.x < b.x) || (a.x == b.x && a.y < b.y);
}
bool operator==(CNode &a, CNode &b) { return a.x == b.x && a.y == b.y; }
const int MAXN = 300000 + 10;
CNode a[MAXN];
int sum[MAXN];
int sum2[MAXN];
int main() {
  int n, p;
  scanf("%d%d", &n, &p);
  memset(sum, 0, sizeof(sum));
  for (int i = 0; i < n; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    x--;
    y--;
    sum[x]++;
    sum[y]++;
    if (x < y) {
      a[i].x = x;
      a[i].y = y;
    } else {
      a[i].x = y;
      a[i].y = x;
    }
  }
  sort(a, a + n);
  for (int i = 0; i < n; ++i) {
    sum2[i] = sum[i];
  }
  sort(sum2, sum2 + n);
  int head = 0, tail = n - 1;
  long long ans = 0;
  while (head < tail) {
    if (sum2[head] + sum2[tail] >= p) {
      ans += tail - head;
      tail--;
    } else {
      head++;
    }
  }
  head = 0;
  tail = 0;
  a[n].x = MAXN;
  a[n].y = MAXN;
  while (tail < n) {
    tail++;
    if (!(a[head] == a[tail])) {
      int x = a[head].x, y = a[head].y;
      if (sum[x] + sum[y] >= p && sum[x] + sum[y] - (tail - head) < p) {
        ans--;
      }
      head = tail;
    }
  }
  cout << ans << endl;
  return 0;
}
