#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline int sz(const T& x) {
  return (int)x.size();
}
template <typename T>
inline void mn(T& x, const T& y) {
  if (y < x) x = y;
}
template <typename T>
inline void mx(T& x, const T& y) {
  if (x < y) x = y;
}
int n, p;
int tree[1 << 20];
int x[300000];
int y[300000];
int vote[300000];
inline void build_tree(int l, int r, int x) {
  tree[x] = 0;
  if (r - l > 1) {
    int m = (l + r) / 2;
    build_tree(l, m, 2 * x + 1);
    build_tree(m, r, 2 * x + 2);
  }
}
inline void tree_add(int dest, int delta, int l, int r, int x) {
  tree[x] += delta;
  if (r - l > 1) {
    int m = (l + r) / 2;
    if (dest < m)
      tree_add(dest, delta, l, m, 2 * x + 1);
    else
      tree_add(dest, delta, m, r, 2 * x + 2);
  }
}
inline int tree_count(int ql, int qr, int l, int r, int x) {
  if (ql <= l && r <= qr) {
    return tree[x];
  }
  if (qr <= l || r <= ql) {
    return 0;
  }
  int m = (l + r) / 2;
  return tree_count(ql, qr, l, m, 2 * x + 1) +
         tree_count(ql, qr, m, r, 2 * x + 2);
}
vector<int> who[300000];
inline void change(const vector<int>& who, int sign) {
  for (int i : who) {
    tree_add(vote[x[i]], -1, 0, n + 1, 0);
    vote[x[i]] += sign;
    tree_add(vote[x[i]], +1, 0, n + 1, 0);
    tree_add(vote[y[i]], -1, 0, n + 1, 0);
    vote[y[i]] += sign;
    tree_add(vote[y[i]], +1, 0, n + 1, 0);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  while (cin >> n >> p) {
    for (int i = 0; i < (n); ++i) {
      vote[i] = 0;
      who[i].resize(0);
    }
    for (int i = 0; i < (n); ++i) {
      cin >> x[i] >> y[i];
      x[i]--, y[i]--;
      who[x[i]].push_back(i);
      vote[x[i]]++;
      who[y[i]].push_back(i);
      vote[y[i]]++;
    }
    build_tree(0, n + 1, 0);
    for (int i = 0; i < (n); ++i) {
      tree_add(vote[i], 1, 0, n + 1, 0);
    }
    long long ans = 0;
    for (int i = 0; i < (n); ++i) {
      change(who[i], -1);
      int need = p - sz(who[i]);
      if (need <= 0) {
        ans += n - 1;
      } else {
        ans += tree_count(need, n + 1, 0, n + 1, 0);
      }
      change(who[i], +1);
    }
    cout << ans / 2 << endl;
  }
  return 0;
}
