#include <bits/stdc++.h>
using namespace std;
int main() {
  int largeN = 998244353;
  int N, K;
  cin >> N >> K;
  int R, L;
  set<int> diff;
  for (int i = 0; i < K; i++) {
    cin >> L >> R;
    for (int j = L; j <= R; j++) {
      diff.insert(j);
    }
  }
  vector<long long> ways_to_N(N);
  ways_to_N[N - 1] = 1;
  for (int i = N - 1; i >= 0; i--) {
    for (int d : diff) {
      if (i - d < 0) break;
      ways_to_N[i - d] += ways_to_N[i];
      ways_to_N[i - d] %= largeN;
    }
  }
  cout << ways_to_N[0] << endl;
}
