#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const int MOD = 998244353;
const int INF32 = 1 << 30;
const long long INF64 = 1LL << 60;
long long sub(long long a, long long b) { return ((a - b) % MOD + MOD) % MOD; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, k;
  cin >> n >> k;
  vector<long long> dp(n + 1);
  vector<long long> pre(n + 1);
  vector<bool> can(n + 2);
  vector<pair<long long, long long>> u;
  dp[1] = pre[1] = 1;
  for (long long i = 0; i < k; i++) {
    long long l, r;
    cin >> l >> r;
    for (long long j = l; j <= r; j++) can[j] = 1;
  }
  for (long long i = 1; i <= n; i++) {
    if (can[i] && !can[i - 1]) u.push_back(make_pair(i, -1));
    if (can[i] && !can[i + 1]) u[u.size() - 1].second = i;
  }
  for (long long i = 2; i <= n; i++) {
    for (pair<long long, long long> x : u) {
      if (i - x.first < 1)
        break;
      else
        dp[i] += sub(pre[i - x.first], pre[max(i - x.second - 1, 0LL)]);
    }
    pre[i] = (pre[i - 1] + dp[i]) % MOD;
  }
  cout << dp[n];
  return 0;
}
