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