#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<int> S;
  for (int i = 0; i < (k); ++i) {
    for (int j = int(l[i]); j < int(r[i] + 1); ++j) S.push_back(j);
  }
  sort((S).begin(), (S).end());
  dp[0] = 1;
  for (int i = 0; i < (n); ++i) {
    for (int j = 0; j < (S.size()); ++j) {
      if ((i - S[j]) >= 0) {
        dp[i] += dp[i - S[j]];
        dp[i] = dp[i] % MOD;
      } else
        break;
    }
  }
  dp[n - 1] = dp[n - 1] % MOD;
  cout << dp[n - 1] << endl;
  return 0;
}
