#include <bits/stdc++.h>
using namespace std;
bool __hack = std::ios::sync_with_stdio(false);
auto __hack1 = cin.tie(nullptr);
namespace template_util {
constexpr int bytecount(uint64_t x) { return x ? 1 + bytecount(x >> 8) : 0; }
template <int N>
struct bytetype {};
template <uint64_t N>
struct minimal_uint : bytetype<bytecount(N)> {};
}  // namespace template_util
template <class T>
T next(istream& in) {
  T ret;
  in >> ret;
  return ret;
}
template <class K, K Z = K()>
struct fenwick {
  vector<K> f;
  function<K(K, K)> op;
  function<bool(K, K)> cmp;
  fenwick(int size, function<K(K, K)> op_ = plus<K>(),
          function<bool(K, K)> cmp_ = less<K>())
      : f(size, Z), op(op_), cmp(cmp_) {}
  K sum(int i) {
    K ret = Z;
    while (i >= 0) {
      ret = op(ret, f[i]);
      i = (i & (i + 1)) - 1;
    }
    return ret;
  }
  void add(int i, K val) {
    while (i < f.size()) {
      f[i] = op(f[i], val);
      i = i | (i + 1);
    }
  }
};
void solve(istream& in, ostream& out) {
  auto n = next<int>(in);
  auto p = next<int>(in);
  vector<int> votes(n, 0);
  map<pair<int, int>, int> pairVotes;
  vector<set<int>> pairVotesDetails(n);
  for (int i = 0; i < (n); ++i) {
    auto x = next<int>(in) - 1;
    auto y = next<int>(in) - 1;
    ++votes[x];
    ++votes[y];
    pairVotes[make_pair(min(x, y), max(x, y))]++;
    pairVotesDetails[x].insert(y);
    pairVotesDetails[y].insert(x);
  }
  int64_t res = 0;
  for (auto& pp : pairVotes) {
    int x = pp.first.first, y = pp.first.second;
    if (votes[x] + votes[y] - pp.second < p && votes[x] + votes[y] >= p) {
      --res;
    }
  }
  fenwick<int> ft(n + 1);
  for (int i = 0; i < (n); ++i) {
    ft.add(votes[i], 1);
  }
  for (int i = 0; i < (n); ++i) {
    ft.add(votes[i], -1);
    int need = max(p - votes[i], 0);
    int s = ft.sum(n);
    if (need > 0) {
      s -= ft.sum(need - 1);
    }
    res += s;
  }
  out << res << "\n";
}
int main() {
  solve(cin, cout);
  return 0;
}
