#include <bits/stdc++.h>
using namespace std;
long long val = 998244353;
vector<long long> S(0);
long long N;
vector<long long> dp;
long long dfs(long long n) {
  if (dp[n] != -1)
    return dp[n];
  else {
    dp[n] = 0;
    for (int j = 0; j < S.size(); j++) {
      if (n + S[j] == N)
        dp[n]++;
      else if (n + S[j] < N) {
        dp[n] += dfs(n + S[j]);
        dp[n] = dp[n] % val;
      } else
        break;
    }
    dp[n] = dp[n] % val;
    return dp[n];
  }
}
int main() {
  int K;
  cin >> N >> K;
  dp = vector<long long>(N + 1, -1);
  for (int i = 0; i < K; i++) {
    long long L, R;
    cin >> L >> R;
    for (int j = L; j <= R; j++) S.push_back(j);
  }
  sort(S.begin(), S.end());
  long long ans = dfs(1);
  cout << ans << endl;
}
