#include <bits/stdc++.h>
using namespace std;
int main() {
  uint64_t n;
  int k;
  cin >> n >> k;
  vector<uint64_t> l(k);
  vector<uint64_t> r(k);
  for (int i = 0; i < k; i++) {
    cin >> l[i] >> r[i];
  }
  sort(l.begin(), l.end());
  sort(r.begin(), r.end());
  vector<uint64_t> a(n + 1, 0);
  a[1] = 1;
  for (int i = l[0]; i <= n; i++) {
    for (int j = 0; j < k; j++) {
      for (int d = l[j]; d <= r[j]; d++) {
        if (d < i) {
          a[i] += a[i - d];
          a[i] %= 998244353;
        } else {
          break;
        }
      }
    }
  }
  cout << a[n] << endl;
}
