#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b);
int lcm(int a, int b);
struct _id {
  int id;
  int num;
} r[300005];
map<pair<int, int>, int> store;
int n, p;
long long ans;
bool cmp(_id a, _id b) {
  if (a.num != b.num)
    return a.num < b.num;
  else
    return a.id < b.id;
}
void Solution() {
  while (cin >> n >> p) {
    ans = 0;
    for (int i = 1; i < (n + 1); i++) {
      r[i].id = i;
      r[i].num = 0;
    }
    for (int i = 0; i < n; i++) {
      int a, b;
      cin >> a >> b;
      (r[a].num)++;
      (r[b].num)++;
      int mn = min(a, b);
      int mx = max(a, b);
      pair<int, int> temp = make_pair(mn, mx);
      if (store.find(temp) != store.end()) {
        store[temp]++;
      } else {
        store.insert(make_pair(temp, 1));
      }
    }
    for (map<pair<int, int>, int>::iterator it = store.begin();
         it != store.end(); it++) {
      pair<int, int> temp = it->first;
      int value = r[temp.first].num + r[temp.second].num;
      if (value >= p && (value - it->second) < p) ans--;
    }
    sort(r + 1, r + n + 1, cmp);
    int last = -1, value = 0;
    for (int i = 1; i < n; i++) {
      if (r[i].num != last) {
        for (int j = (i + 1); j < (n + 1); j++) {
          if (r[i].num + r[j].num >= p) {
            int temp = n - j + 1;
            ans += temp;
            last = r[i].num;
            if (r[i].num * 2 >= p)
              value = temp - 1;
            else
              value = temp;
            break;
          }
        }
      } else {
        ans += value;
        if (r[i].num * 2 >= p) value--;
      }
    }
    cout << ans << endl;
  }
}
int main() {
  Solution();
  return 0;
}
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
