#include <bits/stdc++.h>
using namespace std;
const int maxn = 400000;
int cnt[maxn];
pair<int, int> a[maxn];
int main() {
  int N, P;
  scanf("%d%d", &N, &P);
  for (int i = 0; i < (int)(N); ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    --x;
    --y;
    ++cnt[x];
    ++cnt[y];
    if (x > y) swap(x, y);
    a[i] = make_pair(x, y);
  }
  long long res = 0;
  vector<int> cc(N);
  for (int i = 0; i < (int)(N); ++i) cc[i] = cnt[i];
  sort((cc).begin(), (cc).end());
  int i = 0, j = N;
  while (i < N) {
    while (j > 0 && cc[j - 1] + cc[i] >= P) --j;
    res += (N - max(j, i + 1));
    ++i;
  }
  i = 0;
  sort(a, a + N);
  while (i < N) {
    int j = i;
    while (j < N && a[j] == a[i]) ++j;
    int d = j - i;
    int x = a[i].first, y = a[i].second;
    if (cnt[x] + cnt[y] >= P && cnt[x] + cnt[y] - d < P) --res;
    i = j;
  }
  cout << res << '\n';
  return 0;
}
