#include <bits/stdc++.h>
using namespace std;
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
long long dp[200003];
long long mod = 998244353;
int main() {
  int N, K;
  cin >> N >> K;
  vector<int> S;
  for (long long i = (0); i < (K); ++i) {
    int L, R;
    cin >> L >> R;
    for (long long ii = (L); ii < (R + 1); ++ii) S.emplace_back(ii);
  }
  sort((S).begin(), (S).end());
  memset((dp), 0, sizeof(dp));
  dp[1] = 1;
  for (long long i = (1); i < (N + 1); ++i) {
    for (long long k = (0); k < (int((S).size())); ++k)
      if (i >= S[k]) {
        dp[i] = (dp[i] + dp[i - S[k]]) % mod;
      }
  }
  cout << dp[N] % mod << endl;
  return 0;
}
