#include <bits/stdc++.h>
using namespace std;
vector<long long int> second;
long long int mod = 998244353;
long long int solve(long long int SUM, vector<long long int>& X) {
  if (X.at(SUM) == -1) {
    long long int ans = 0;
    for (long long int i = 0; i < second.size() && second.at(i) <= SUM; i++) {
      ans += solve(SUM - second.at(i), X);
      ans %= mod;
      if (X.at(SUM) != -1) break;
    }
    if (X.at(SUM) == -1) X.at(SUM) = ans % mod;
  }
  return X.at(SUM);
}
signed main() {
  long long int N, K, i, j, L, R;
  cin >> N >> K;
  vector<long long int> X(N, -1);
  for (i = 0; i < K; i++) {
    cin >> L >> R;
    for (j = L; j < R + 1; j++) second.push_back(j);
  }
  sort(second.begin(), second.end());
  for (i = 0; i < second.at(0); i++) X.at(i) = 0;
  X.at(i) = 1;
  X.at(0) = 1;
  cout << solve(N - 1, X) << endl;
  return 0;
}
