#include <bits/stdc++.h>
using namespace std;
const int maxn = 300010;
int n, p;
int num[maxn], old[maxn];
int sum[maxn];
int first[maxn];
struct Arc {
  int v, next;
} arc[maxn];
int cnt;
void add2(int u, int v) {
  arc[cnt].v = v;
  arc[cnt].next = first[u];
  first[u] = cnt++;
}
void add(int i, int c) {
  i++;
  for (; i <= n + 1; i += i & (-i)) sum[i] += c;
}
int ask(int i) {
  i++;
  int ans = 0;
  for (; i > 0; i -= i & (-i)) ans += sum[i];
  return ans;
}
long long solve() {
  for (int i = 1; i <= n; i++) old[i] = num[i];
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    ans += i - 1 - ask(p - num[i] - 1);
    for (int j = first[i]; j + 1; j = arc[j].next) {
      int k = arc[j].v;
      num[k]--;
    }
    for (int j = first[i]; j + 1; j = arc[j].next) {
      int k = arc[j].v;
      if (old[k] == num[k]) continue;
      if (old[k] + num[i] >= p && num[k] + num[i] < p) ans--;
      num[k] = old[k];
    }
    add(num[i], 1);
  }
  return ans;
}
int main() {
  while (scanf("%d%d", &n, &p) == 2) {
    for (int i = 1; i <= n + 1; i++) num[i] = sum[i] = 0, first[i] = -1;
    cnt = 0;
    for (int i = 1; i <= n; i++) {
      int x, y;
      scanf("%d%d", &x, &y);
      if (x > y) swap(x, y);
      num[x]++;
      num[y]++;
      add2(y, x);
    }
    printf("%I64d\n", solve());
  }
  return 0;
}
