#include <bits/stdc++.h>
using namespace std;
int n, p;
long long ans = 0;
int A[300009][2];
int fr[300009];
map<int, int> F[300009];
int T[300009];
class AVL {
 private:
  vector<int> D, L, R, H, C;
  int sz, nm, root, tmp;
  int rot_left(int node) {
    tmp = R[node];
    R[node] = L[R[node]];
    L[tmp] = node;
    ((H[node] = (H[L[node]] > H[R[node]] ? H[L[node]] : H[R[node]]) + 1),
     (C[node] = C[L[node]] + C[R[node]] + 1));
    ((H[tmp] = (H[L[tmp]] > H[R[tmp]] ? H[L[tmp]] : H[R[tmp]]) + 1),
     (C[tmp] = C[L[tmp]] + C[R[tmp]] + 1));
    return tmp;
  }
  int rot_right(int node) {
    tmp = L[node];
    L[node] = R[L[node]];
    R[tmp] = node;
    ((H[node] = (H[L[node]] > H[R[node]] ? H[L[node]] : H[R[node]]) + 1),
     (C[node] = C[L[node]] + C[R[node]] + 1));
    ((H[tmp] = (H[L[tmp]] > H[R[tmp]] ? H[L[tmp]] : H[R[tmp]]) + 1),
     (C[tmp] = C[L[tmp]] + C[R[tmp]] + 1));
    return tmp;
  }
  int fix(int node) {
    ((H[node] = (H[L[node]] > H[R[node]] ? H[L[node]] : H[R[node]]) + 1),
     (C[node] = C[L[node]] + C[R[node]] + 1));
    if (H[L[node]] > H[R[node]] + 1) {
      if (H[R[L[node]]] > H[L[L[node]]]) L[node] = rot_left(L[node]);
      node = rot_right(node);
    } else if (H[R[node]] > H[L[node]] + 1) {
      if (H[L[R[node]]] > H[R[R[node]]]) R[node] = rot_right(R[node]);
      node = rot_left(node);
    }
    return node;
  }
  int _add(int node, int x) {
    if (D[node] == x && node) return node;
    if (!node) {
      sz++;
      nm++;
      D[sz] = x;
      H[sz] = C[sz] = 1;
      return sz;
    }
    if (x < D[node])
      L[node] = _add(L[node], x);
    else
      R[node] = _add(R[node], x);
    return fix(node);
  }
  int _del(int node, int x) {
    if (!node) return 0;
    if (D[node] == x) {
      if (!L[node] || !R[node]) return (!L[node] ? R[node] : L[node]);
      for (tmp = L[node]; R[tmp]; tmp = R[tmp])
        ;
      D[node] = D[tmp];
      L[node] = _del(L[node], D[tmp]);
      return fix(node);
    }
    if (x < D[node])
      L[node] = _del(L[node], x);
    else
      R[node] = _del(R[node], x);
    return fix(node);
  }
  int _kth(int node, int x) {
    if (C[L[node]] + 1 == x) return D[node];
    if (C[L[node]] + 1 < x) return _kth(R[node], x - 1 - C[L[node]]);
    return _kth(L[node], x);
  }
  int _isin(int node, int x) {
    if (!node) return 0;
    if (D[node] == x) return 1;
    if (D[node] < x) return _isin(R[node], x);
    return _isin(L[node], x);
  }
  int _find(int node, int x) {
    if (!node) return 0;
    if (D[node] <= x) return 1 + C[L[node]] + _find(R[node], x);
    return _find(L[node], x);
  }
  int _lower_bound(int node, int x) {
    if (x == D[node]) return x;
    if (x > D[node]) return (R[node] ? _lower_bound(R[node], x) : D[node]);
    for (tmp = L[node]; R[tmp]; tmp = R[tmp])
      ;
    if (!tmp || D[tmp] < x) return D[node];
    return _lower_bound(L[node], x);
  }

 public:
  int size() { return nm; };
  int isempty() { return nm == 0; }
  void add(int x) { root = _add(root, x); }
  int lower_bound(int x) { return _lower_bound(root, x); }
  int kth(int x) { return (nm ? _kth(root, (x < nm ? x : nm)) : 0); }
  int find(int x) { return (_isin(root, x) == 0 ? 0 : _find(root, x)); }
  void del(int x) {
    nm -= _isin(root, x);
    if (root) root = _del(root, x);
  }
  void maxsize(int x) {
    L = R = H = C = vector<int>(x + 1, 0), D = vector<int>(x + 1, 0),
    root = sz = nm = 0;
  }
} st;
int main() {
  scanf("%d %d", &n, &p);
  for (int i = 0; i < n; i++) {
    scanf("%d %d", &A[i][0], &A[i][1]);
    fr[A[i][0]]++;
    fr[A[i][1]]++;
    F[A[i][0]][A[i][1]]++;
    F[A[i][1]][A[i][0]]++;
  }
  for (int i = 1; i <= n; i++) T[i - 1] = fr[i];
  sort(T, T + n);
  for (int i = 1; i <= n; i++) {
    p -= fr[i];
    ans += n - (lower_bound(T, T + n, p) - T);
    for (__typeof((F[i]).begin()) j = (F[i]).begin(); j != (F[i]).end(); j++) {
      int man = j->first;
      if (fr[man] - j->second < p && fr[man] >= p) ans--;
    }
    p += fr[i];
    ans -= (fr[i] * 2 >= p);
  }
  printf("%I64d", ans / 2);
}
