#include <bits/stdc++.h>
using namespace std;
int main(void) {
  long long N, K;
  cin >> N >> K;
  vector<pair<long long, long long> > ranges(K);
  vector<long long> diffs(N + 1, 0);
  vector<long long> paths(N + 1, 0);
  paths[1] = 1;
  long long cur = 0;
  for (long long i = 0; i < K; i++) {
    int l, r;
    cin >> l >> r;
    ranges[i] = make_pair(l, r);
  }
  for (long long i = 1; i <= N; i++) {
    cur += diffs[i];
    paths[i] += cur;
    paths[i] = paths[i] % 998244353;
    if (paths[i] > 0) {
      for (long long j = 0; j < K; j++) {
        if (i + ranges[j].first <= N) {
          diffs[i + ranges[j].first] += paths[i];
          diffs[min(N + 1, i + ranges[j].second + 1)] -= paths[i];
        }
      }
    }
  }
  cout << paths[N] << endl;
  return 0;
}
