#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, K;
  cin >> N >> K;
  int l, r;
  vector<int> steps;
  for (int i = 0; i < K; i++) {
    cin >> l >> r;
    for (int j = l; j < r + 1; j++) steps.push_back(j);
  }
  vector<long long> dp(N);
  dp[0] = 1;
  for (int i = 0; i < N; i++) {
    for (int& step : steps) {
      if (i + step < N) {
        dp[i + step] += dp[i];
      }
    }
  }
  cout << dp[N - 1] % 998244353 << endl;
  return 0;
}
