#include <bits/stdc++.h>
using namespace std;
long long MOD = 998244353;
int main(void) {
  long long N, K;
  set<long long> S_tmp;
  cin >> N >> K;
  long long L, R;
  vector<long long> M(N + 5, 0);
  for (long long i = 0; i < K; i++) {
    cin >> L >> R;
    for (long long l = L; l <= R; l++) {
      S_tmp.insert(l);
    }
  }
  vector<long long> S;
  for (auto i : S_tmp) {
    S.push_back(i);
  }
  sort(S.begin(), S.end());
  M[1] = 1;
  for (long long i = 1; i <= N;) {
    if (M[i] <= 0) {
      continue;
    }
    for (long long x = 0; x < S.size(); x++) {
      if (i + S[x] <= N) {
        M[i + S[x]] += M[i] % MOD;
        M[i + S[x]] = (M[i + S[x]] + MOD) % MOD;
      }
    }
    i += S[0];
  }
  cout << M[N] << endl;
  return 0;
}
