#include #include #include #include #include #include #include using namespace std; using ll = long long; struct BIT { BIT(int n) : b(n + 1), n(n) {} void add(int i, int v) { for (int k = i + 1; k <= n; k += k & -k) b[k] += v; } int sum(int k) { int s = 0; for (; k > 0; k -= k & -k) s += b[k]; return s; } vector b; int n; }; struct E { bool operator<(const E& e) const { return a < e.a; } int a, b; }; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; vector e(n); for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; if (a > b) swap(a, b); e[i] = { a, b }; } sort(e.begin(), e.end()); BIT bt(m); ll r = 0; for (int i = 0; i < n; i++) { r += bt.sum(e[i].b) - bt.sum(e[i].a); bt.add(e[i].b, 1); } cout << r << endl; return 0; }