#include <bits/stdc++.h>
using namespace std;
int main() {
  int P = 998244353;
  int N, K;
  vector<int> s;
  cin >> N >> K;
  for (int i = 0; i < K; ++i) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; ++j) {
      s.push_back(j);
    }
  }
  sort(s.begin(), s.end());
  vector<int> c(N + 1, 0);
  for (size_t j = 0; j < s.size(); ++j) {
    if (s[j] + 1 <= N) {
      c[s[j] + 1] = 1;
    }
  }
  for (int i = 1; i <= N; ++i) {
    for (size_t j = 0; j < s.size(); ++j) {
      if ((i - s[j]) >= 0) {
        c[i] = (c[i] + c[i - s[j]]) % P;
      } else {
        break;
      }
    }
  }
  cout << c[N] << endl;
  return 0;
}
