#include <bits/stdc++.h>
using namespace std;
long long MOD = 998244353;
long long dp[1000005];
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> l(k);
  vector<int> r(k);
  for (int i = 0; i < (k); ++i) cin >> l[i] >> r[i];
  vector<long long> wa(n + 1);
  dp[0] = 1;
  wa[0] = 0;
  for (int i = 0; i < (n); ++i) {
    for (int j = 0; j < (k); ++j) {
      if (i - r[j] >= 0) {
        dp[i] += (wa[i - l[j] + 1] - wa[i - r[j]]) % MOD;
      } else if (i - l[j] >= 0) {
        dp[i] += (wa[i - l[j] + 1] - wa[0]) % MOD;
      }
    }
    wa[i + 1] += (wa[i] + dp[i]) % MOD;
  }
  dp[n - 1] = dp[n - 1] % MOD;
  cout << dp[n - 1] << endl;
  return 0;
}
