#include <bits/stdc++.h>
using namespace std;
int n, p, a[300005], b[300005], x, y, z;
int qty[300005], sum[300005], chosenKtimes[300005];
vector<int> v[300005], temp;
long long sol = 0LL;
map<pair<int, int>, int> together;
int main() {
  cin >> n >> p;
  for (int i = 1; i <= n; i++) {
    cin >> a[i] >> b[i];
    v[a[i]].push_back(b[i]);
    v[b[i]].push_back(a[i]);
    x = min(a[i], b[i]);
    y = max(a[i], b[i]);
    if (together.find(make_pair(x, y)) == together.end())
      together[make_pair(x, y)] = 0;
    together[make_pair(x, y)]++;
    qty[a[i]]++;
    qty[b[i]]++;
  }
  for (int i = 1; i <= n; i++) {
    temp.clear();
    for (int j = 0; j < int(v[i].size()); j++) temp.push_back(v[i][j]);
    sort(temp.begin(), temp.end());
    v[i].clear();
    if (!temp.empty()) v[i].push_back(temp[0]);
    for (int j = 1; j < int(temp.size()); j++)
      if (temp[j] != temp[j - 1]) v[i].push_back(temp[j]);
  }
  for (int i = 1; i <= n; i++) chosenKtimes[qty[i]]++;
  for (int i = n; i >= 0; i--) sum[i] = sum[i + 1] + chosenKtimes[i];
  for (int x = 1; x <= n; x++) {
    sol += 1LL * sum[max(0, p - qty[x])];
    if (2 * qty[x] >= p) sol -= 1LL;
    for (int j = 0; j < int(v[x].size()); j++) {
      y = v[x][j];
      z = 0;
      if (together.find(make_pair(min(x, y), max(x, y))) != together.end())
        z = together[make_pair(min(x, y), max(x, y))];
      if (qty[x] + qty[y] >= p && qty[x] + qty[y] - z < p) sol -= 1LL;
    }
  }
  sol /= 2LL;
  cout << sol << "\n";
  return 0;
}
