#include #include using namespace std; int main() { int n,m; cin >> n >> m; vector a, b; int ans = 0; for (int i = 0; i < n; i++) { int _a, _b; cin >> _a >> _b; if (_b < _a) { int temp = _a; _a = _b; _b = temp; } a.push_back(_a); b.push_back(_b); for (int k = 0; k < i; k++) { if ((a[k] < _a && _a < b[k]) && (a[k] < _b && _b < b[k])) { continue; } if ((a[k] < _a && _a < b[k]) || (a[k] < _b && _b < b[k])) { ans++; } } } cout << ans << endl; return 0; }