#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
long long dp[200001];
int main() {
  int N, K;
  cin >> N >> K;
  vector<int> step;
  for (int i = 0; i < K; i++) {
    int L, R;
    cin >> L >> R;
    for (int j = L; j <= R; j++) {
      step.push_back(j);
    }
  }
  dp[1] = 1;
  for (int i = 1; i < N; i++) {
    for (int s : step) {
      if (i + s > N) continue;
      dp[i + s] = (dp[i + s] + dp[i]) % MOD;
    }
  }
  long long ans = dp[N];
  cout << ans << endl;
  return 0;
}
