#include <bits/stdc++.h>
using namespace std;
int N, K;
int L[15], R[15];
vector<int> step;
long long dp[202020];
long long ans(int N) {
  if (N == 1) return 1LL;
  if (dp[N] != -1) return dp[N];
  long long ret = 0;
  for (auto it = step.begin(); it != step.end(); it++) {
    if (N - (*it) >= 1) {
      ret += ans(N - (*it));
      ret %= 998244353;
    }
  }
  return dp[N] = ret;
}
int main() {
  cin >> N >> K;
  for (size_t i = 0; i < K; i++) {
    cin >> L[i] >> R[i];
    for (int s = L[i]; s <= R[i]; s++) {
      step.push_back(s);
    }
  }
  for (int i = 0; i < 202020; i++) {
    dp[i] = -1;
  }
  cout << ans(N) << endl;
}
