#include <bits/stdc++.h>
using namespace std;
const int MN = 300010;
int N, P;
vector<pair<int, int> > S;
int deg[300010];
map<pair<int, int>, int> cnt;
struct Fenwick {
  int tree[MN + 1];
  void init() { memset(tree, 0, sizeof(tree)); }
  void upd(int idx, int val) {
    for (int i = idx + 1; i <= MN; i += (i & -i)) tree[i] += val;
  }
  int quer(int a) {
    if (a >= MN) a = MN - 1;
    int ret = 0;
    for (int i = a + 1; i >= 1; i -= (i & -i)) ret += tree[i];
    return ret;
  }
  int quer(int a, int b) { return quer(b) - quer(a - 1); }
} bit;
int main() {
  scanf("%d %d", &N, &P);
  S.resize(N);
  for (int i = 0; i < N; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    x--;
    y--;
    if (x > y) swap(x, y);
    S[i] = pair<int, int>(x, y);
    deg[x]++;
    deg[y]++;
    cnt[S[i]]++;
  }
  sort(S.begin(), S.end());
  S.resize(unique(S.begin(), S.end()) - S.begin());
  bit.init();
  long long ans = 0;
  int pos = (int)S.size() - 1;
  for (int i = N - 1; i >= 0; i--) {
    ans += bit.quer(P - deg[i], MN - 1);
    while (pos >= 0 && S[pos].first == i) {
      if (deg[i] + deg[S[pos].second] >= P &&
          deg[i] + deg[S[pos].second] - cnt[S[pos]] < P) {
        ans--;
      }
      pos--;
    }
    bit.upd(deg[i], 1);
  }
  printf("%lld", ans);
}
