#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
void run() {
  const i64 mod{998244353};
  i64 n, k;
  cin >> n >> k;
  vector<i64> ls(k), rs(k);
  for (i64 i = (0); i < (k); ++i) {
    cin >> ls[i] >> rs[i];
  }
  vector<i64> counts(n + 1);
  vector<i64> incs(n + 1);
  incs[1] = 1;
  incs[2] = -1;
  for (i64 i = (1); i < (n + 1); ++i) {
    counts[i] = (counts[i - 1] + incs[i]) % mod;
    for (i64 ik = (0); ik < (k); ++ik) {
      i64 il{i + ls[ik]}, ir{i + rs[ik] + 1};
      if (il < n + 1) {
        incs[il] += counts[i];
        if (ir < n + 1) {
          incs[ir] -= counts[i];
        }
      }
    }
  }
  cout << counts[n] << endl;
}
int main() {
  cin.tie(nullptr);
  run();
  return 0;
}
