#include <bits/stdc++.h>
using namespace std;
vector<long long int> S;
long long int N, K;
void solve() {
  cin >> N >> K;
  while (K--) {
    long long int l, r;
    cin >> l >> r;
    for (long long int i = l; i <= r; i++) S.push_back(i);
  }
  sort(S.begin(), S.end());
  vector<long long int> dp(N + 1, 0);
  dp[1] = 1;
  long long int M = S.size();
  for (long long int i = 2; i <= N; i++) {
    for (long long int j = 0; j < M && S[j] < i; j++) {
      dp[i] += dp[i - S[j]];
      dp[i] %= (998244353);
    }
  }
  cout << dp[N] << endl;
}
clock_t startTime;
double getCurrentTime() {
  return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int T;
  T = 1;
  while (T--) {
    solve();
  }
  return 0;
}
