#include <bits/stdc++.h>
using namespace std;
const int MN = 300111;
int n, p;
map<int, int> ke[MN];
int deg[MN], actual[MN];
int main() {
  ios ::sync_with_stdio(false);
  cin.tie(NULL);
  cout << (fixed) << setprecision(6);
  while (cin >> n >> p) {
    for (int i = (1), _b = (n); i <= _b; i++) ke[i].clear();
    for (int i = (1), _b = (n); i <= _b; i++) deg[i] = actual[i] = 0;
    for (int i = (1), _b = (n); i <= _b; i++) {
      int u, v;
      cin >> u >> v;
      ke[u][v] += 1;
      ke[v][u] += 1;
      deg[u]++;
      deg[v]++;
    }
    for (int i = (1), _b = (n); i <= _b; i++) actual[i] = deg[i];
    sort(deg + 1, deg + n + 1);
    long long res = 0;
    for (int i = (1), _b = (n); i <= _b; i++) {
      int need = p - actual[i];
      if (deg[1] >= need) {
        res += n - 1;
      } else if (deg[n] < need) {
      } else {
        int id = lower_bound(deg + 1, deg + n + 1, need) - deg;
        if (actual[i] >= need) ++id;
        res += (n - id + 1);
      }
      for (pair<int, int> cur : ke[i]) {
        int v = cur.first;
        if (actual[v] >= need) --res;
        if (actual[v] + actual[i] - cur.second >= p) ++res;
      }
    }
    cout << res / 2 << endl;
  }
  return 0;
}
