#include #include using namespace std; using ll = long long; #define rep(i, s, t) for (ll i = s; i < (ll)(t); i++) #define all(x) begin(x), end(x) template bool chmin(T& x, T y) { return x > y ? (x = y, true) : false; } template bool chmax(T& x, T y) { return x < y ? (x = y, true) : false; } struct io_setup { io_setup() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(15); } } io_setup; using mint = atcoder::modint998244353; // template atcoder lazy segtree using S = ll; S op(S a, S b) { return max(a, b); } S e() { return 0; } using F = ll; S mapping(F f, S x) { return f ^ x; } F comp(F f, F g) { return f ^ g; } F id() { return 0; } using segtree = atcoder::lazy_segtree; void solve() { ll n, m; cin >> n >> m; vector l(m), r(m); rep(i, 0, m) cin >> l[i] >> r[i], l[i]--; vector cv = {0, n}; rep(i, 0, m) { cv.push_back(l[i]); cv.push_back(r[i]); } sort(cv.begin(), cv.end()); cv.erase(unique(cv.begin(), cv.end()), cv.end()); int k = cv.size(); auto get_ith = [&](ll x) { return lower_bound(cv.begin(), cv.end(), x) - cv.begin(); }; segtree seg(k); { random_device rd; mt19937 mt(rd()); rep(i, 0, m) { int nl = get_ith(l[i]); int nr = get_ith(r[i]); seg.apply(nl, nr, mt()); } } map mp; rep(i, 0, k - 1) { mp[seg.get(i)] += cv[i + 1] - cv[i]; } mint ans = 0; { mint tmp = mp[0] + (n - mp[0]) / 2; ans += tmp * tmp; mp.erase(0); } for (auto [hs, ad] : mp) { ans += ad * ad / 4; } ans *= mint(2).pow(m); cout << ans.val() << '\n'; } int main() { int t = 1; // cin >> t; while (t--) solve(); }