#include using namespace std; #define REP(i,a,n) for(int i=(a); i<(int)(n); i++) #define rep(i,n) REP(i,0,n) #define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it) #define ALLOF(c) (c).begin(), (c).end() typedef long long ll; typedef unsigned long long ull; struct FenwickTree{ static const int SIZE = 1<<17; int n, tree[SIZE+1]; public: FenwickTree(int n_){ n = n_; for(int i=0; i=0; i=(i&i+1)-1) s += tree[i]; return s; } }; struct ST { int a, b; }; bool operator<(const ST& a, const ST& b){ return a.a < b.a; } int main(){ int N, M; cin >> N >> M; vector v; rep(i,N){ int a, b; cin >> a >> b; if(a > b) swap(a,b); v.push_back((ST){a,b}); } sort(ALLOF(v)); FenwickTree ft(M+1); ll ret = 0; rep(i,N){ int a = v[i].a, b = v[i].b; ll tmp = ft.sum(b) - ft.sum(a); ret += tmp; ft.add(b, 1); } cout << ret << endl; return 0; }