#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000000;
const int MOD = 1000000007;
const double pi = acos(-1.0);
const int N = 300009;
vector<int> g[N + 1];
int x[N + 1], y[N + 1], C[N + 1];
int main() {
  int n, p;
  cin >> n >> p;
  for (int i = (1); i <= (n); ++i) {
    scanf("%d %d", &x[i], &y[i]);
    g[x[i]].push_back(i);
    g[y[i]].push_back(i);
    C[x[i]]++;
    C[y[i]]++;
  }
  vector<int> r;
  for (int i = (1); i <= (n); ++i) r.push_back((int)((g[i]).size()));
  sort(r.begin(), r.end());
  long long ans = 0;
  for (int i = (1); i <= (n); ++i) {
    int need = p - (int)((g[i]).size());
    int posit = lower_bound(r.begin(), r.end(), need) - r.begin();
    int cnt = n - posit;
    if ((int)((g[i]).size()) >= need) --cnt;
    for (int j = (0); j <= ((int)((g[i]).size()) - 1); ++j) {
      int who = g[i][j];
      int other = x[who] + y[who] - i;
      if (C[other] == need) --cnt;
      C[other]--;
    }
    ans += cnt;
    for (int j = (0); j <= ((int)((g[i]).size()) - 1); ++j) {
      int who = g[i][j];
      int other = x[who] + y[who] - i;
      C[other]++;
    }
  }
  cout << ans / 2 << endl;
}
