#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N;
  int K;
  cin >> N >> K;
  long long buffer1, buffer2;
  vector<pair<long long, long long>> W(K);
  vector<long long> path(N + 1);
  path.at(N) = 1;
  for (int i = 0; i < K; i++) {
    cin >> buffer1 >> buffer2;
    W.at(i) = make_pair(buffer1, buffer2);
  }
  for (long long i = 0; i < N; i++) {
    path.at(i) = 0;
  }
  for (long long j = N - 1; j > 0; j--) {
    for (long long i = 0; i < K; i++) {
      for (long long k = W.at(i).first; k <= W.at(i).second; k++) {
        if (j + k <= N) {
          path.at(j) += path.at(j + k);
          path.at(j) %= 998244353;
        }
      }
    }
  }
  cout << path.at(1) << endl;
}
