#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = 1001001001;
const long long MOD = 998244353;
const double EPS = 1e-10;
template <typename T>
struct BIT {
  ll n = 0, msb = 0;
  vector<T> d;
  BIT(ll m) : d(m + 1) {
    n = d.size();
    for (ll i = 31; i >= 0; i--) {
      if (n >> i & 1) {
        msb = i;
        break;
      }
    }
  }
  void add(ll i, T x) {
    while (x < 0) x += MOD;
    x %= MOD;
    while (i < n) {
      d[i] += x;
      while (d[i] < 0) d[i] += MOD;
      d[i] %= MOD;
      i += i & -i;
    }
  }
  T sum(ll i) {
    T res = T();
    while (i > 0) {
      res += d[i];
      while (res < 0) res += MOD;
      res %= MOD;
      i -= i & -i;
    }
    return res;
  }
};
template <typename T>
struct RangeAddBIT {
  BIT<ll> bit0, bit1;
  RangeAddBIT(ll n) : bit0(n + 1), bit1(n + 1) {}
  void add(ll l, ll r, T x) {
    bit0.add(l, -x * (l - 1));
    bit1.add(l, x);
    bit0.add(r + 1, x * r);
    bit1.add(r + 1, -x);
  }
  T sum(ll i) { return ((bit1.sum(i) * i) % MOD + bit0.sum(i)) % MOD; }
};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, k;
  cin >> n >> k;
  ll l[k], r[k];
  int cnt[202020] = {};
  vector<pair<ll, ll>> lr;
  for (int i = 0; i < k; i++) {
    cin >> l[i] >> r[i];
    cnt[l[i]]++;
    cnt[r[i] + 1]--;
  }
  for (int i = 1; i < 202020; i++) cnt[i] += cnt[i - 1];
  int le = -1, ri = -1;
  for (int i = 0; i < 202020; i++) {
    if (cnt[i] == 0) {
      if (lr.empty()) {
        if (le == -1)
          continue;
        else {
          lr.emplace_back(pair<int, int>(le, ri));
          le = ri = -1;
        }
      } else if (le != -1) {
        lr.emplace_back(pair<int, int>(le, ri));
        le = ri = -1;
      }
    } else {
      if (le == -1) {
        le = ri = i;
      } else {
        ri++;
      }
    }
  }
  RangeAddBIT<ll> bit(202020);
  bit.add(1, 1, 1);
  for (int i = 1; i < n; i++) {
    ll t = bit.sum(i) - bit.sum(i - 1);
    while (t < 0) t += MOD;
    t %= MOD;
    for (int j = 0; j < lr.size(); j++) {
      ll x = i + lr[j].first, y = i + lr[j].second;
      if (x > n) continue;
      y = min(y, n);
      bit.add(x, y, t);
    }
  }
  ll ans = bit.sum(n) - bit.sum(n - 1);
  while (ans < 0) ans += MOD;
  ans %= MOD;
  cout << ans << endl;
}
