#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void smin(T &a, U b) {
  if (a > b) a = b;
}
template <typename T, typename U>
inline void smax(T &a, U b) {
  if (a < b) a = b;
}
int a[300300], b[300300];
int cnt[300300], arr[300300];
vector<int> adj[300300];
int main() {
  int n, p;
  cin >> n >> p;
  for (int i = 1; i <= n; i++) {
    scanf("%d %d", a + i, b + i);
    cnt[a[i]]++;
    cnt[b[i]]++;
    adj[a[i]].push_back(i);
    adj[b[i]].push_back(i);
  }
  for (int i = 1; i <= n; i++) arr[i] = cnt[i];
  sort(arr + 1, arr + n + 1);
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    int ct = cnt[i];
    if (ct >= p) {
      ans += n - 1;
      continue;
    }
    int tmp = p - ct;
    int res = n - (lower_bound(arr, arr + n + 1, tmp) - arr) + 1;
    for (int j = 0; j < adj[i].size(); j++) {
      int k = adj[i][j];
      if (cnt[a[k]]-- == tmp) res--;
      if (cnt[b[k]]-- == tmp) res--;
    }
    ans += res;
    for (int j = 0; j < adj[i].size(); j++) {
      int k = adj[i][j];
      cnt[a[k]]++;
      cnt[b[k]]++;
    }
  }
  cout << ans / 2 << endl;
  return 0;
}
