#include #define all(v) v.begin(), v.end() #define fast cin.tie(nullptr); ios_base::sync_with_stdio(false) using namespace std; using ll = long long; using ull = unsigned long long; constexpr ll mod = 998244353; struct Event{ ll pos; ll type; ll idx; bool operator<(const Event &e) const { if(pos != e.pos) return pos < e.pos; return type < e.type; } }; void zobrist_init(vector &a){ mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); for(int i = 0; i < a.size(); i++) a[i] = rng(); } int main(){ fast; ll n,m,l,r,two_pow = 748683265;// 4^{-1} mod 998244353 vector events; cin >> n >> m; for(int i = 0; i < m; i++){ cin >> l >> r; events.push_back({l, 0, i}); events.push_back({r + 1, 1, i}); two_pow = (two_pow << 1) % mod; } vector zobrist(m + 1); zobrist_init(zobrist); sort(all(events)); map t; ll last = 1; ull hash = 0; for(auto&e : events){ ll now = e.pos; if(now > last) t[hash] = (t[hash] + (now - last)) % mod; hash ^= zobrist[e.idx]; last = now; } if(last <= n) t[hash] = (t[hash] + (n - last + 1)) % mod; ll n0 = t[0],p = 0; for(auto&[h,w] : t){ if(h) p = (p + w * (w - 1)) % mod; } ll ans = ((n + n0) % mod) % mod; ans = (ans * ((n + n0) % mod)) % mod; ans = (ans + n + p - n0) % mod; ans = (ans * two_pow) % mod; cout << ans << endl; }