#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int M = 998244353;
int main(void) {
  int n, k;
  cin >> n >> k;
  vector<int> l(k), r(k), s, d(n, 0);
  for (int i = 0; i < k; i++) {
    cin >> l[i] >> r[i];
  }
  for (int i = 0; i < k; i++) {
    for (int j = l[i]; j <= r[i]; j++) {
      s.push_back(j);
    }
  }
  sort(s.begin(), s.end());
  d[0] = 1;
  for (int i = 1; i < n; i++) {
    for (int j : s) {
      if (0 <= i - j) {
        d[i] += d[i - j];
        d[i] = d[i] % M;
      } else {
        continue;
      }
    }
  }
  cout << d[n - 1] << endl;
  return 0;
}
