#include <bits/stdc++.h>
using namespace std;
function<void(void)> ____ = []() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
};
const int MAXN = 3e5 + 7;
map<pair<int, int>, int> msk;
int n, p, cnt[MAXN];
struct SegmentTree {
  int val[MAXN << 2], l[MAXN << 2], r[MAXN << 2];
  inline int ls(int rt) { return rt << 1; }
  inline int rs(int rt) { return rt << 1 | 1; }
  void pushup(int rt) { val[rt] = val[ls(rt)] + val[rs(rt)]; }
  void build(int L, int R, int rt) {
    l[rt] = L, r[rt] = R;
    if (L + 1 == R) return;
    int mid = (L + R) >> 1;
    build(L, mid, ls(rt));
    build(mid, R, rs(rt));
  }
  void update(int pos, int rt, int x) {
    if (l[rt] + 1 == r[rt]) {
      val[rt] += x;
      return;
    }
    int mid = (l[rt] + r[rt]) >> 1;
    if (pos < mid)
      update(pos, ls(rt), x);
    else
      update(pos, rs(rt), x);
    pushup(rt);
  }
  int query(int L, int R, int rt) {
    if (l[rt] >= R || L >= r[rt]) return 0;
    if (L <= l[rt] && r[rt] <= R) return val[rt];
    return query(L, R, ls(rt)) + query(L, R, rs(rt));
  }
} ST;
int main() {
  scanf("%d %d", &n, &p);
  for (int i = 1; i <= n; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    if (a > b) swap(a, b);
    cnt[a]++;
    cnt[b]++;
    msk[make_pair(a, b)]++;
  }
  ST.build(0, n + 1, 1);
  int_fast64_t tot = 0;
  for (int i = 1; i <= n; i++) {
    int lt = p - cnt[i];
    tot += ST.query(max(0, lt), n + 1, 1);
    ST.update(cnt[i], 1, 1);
  }
  for (auto q : msk) {
    int a = q.first.first;
    int b = q.first.second;
    int ct = q.second;
    if (cnt[a] + cnt[b] >= p && cnt[a] + cnt[b] - ct < p) tot--;
  }
  cout << tot << endl;
  return 0;
}
