#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> l(k), r(k);
  for (int i = 0; i < (k); i++) cin >> l[i] >> r[i];
  vector<long long> dict(n, 0);
  dict[0] = 1;
  for (int i = 1; i < (n); i++) {
    for (int j = 0; j < (k); j++) {
      if (i - l[j] >= 0) {
        int tmp = l[j];
        while (tmp <= r[j] && (i - tmp) >= 0) {
          dict[i] += dict[i - tmp];
          tmp++;
        }
      }
    }
  }
  cout << dict[n - 1] % 998244353 << endl;
}
