#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
using namespace std;
const int maxn=330000;
typedef long long int LL;
map<pair<int,int>, int> tu;
int agree[maxn];
int main()
{
int n,p;
scanf("%d%d",&n,&p);
for(int i=1;i<=n;i++)
{
int u,v;
scanf("%d%d",&u,&v);
if(u>v) swap(u,v);
agree[u]++; agree[v]++;
tu[make_pair(u,v)]++;
}
LL ans=0;
map<pair<int,int> ,int>::iterator it;
for(it=tu.begin();it!=tu.end();it++)
{
int u=it->first.first,v=it->first.second;
int res=agree[u]+agree[v];
if(res>=p&&res-it->second<p)
ans--;
}
int now=n;
sort(agree+1,agree+1+n);
for(int i=1;i<=n;i++)
{
now=max(i,now);
while(i<now&&agree[i]+agree[now]>=p) now--;
ans+=n-now;
}
printf("%I64d\n",ans);
return 0;
}