#include <bits/stdc++.h>
using namespace std;
int main() {
  int64_t N, K;
  cin >> N >> K;
  priority_queue<int64_t, vector<int64_t>, greater<int64_t>> d;
  int64_t tempL, tempR;
  for (int64_t i = 0; i < K; i++) {
    cin >> tempL >> tempR;
    for (int64_t j = tempL; j <= tempR; j++) {
      d.push(j);
    }
  }
  vector<int64_t> X(N + 1, 0);
  X[1] = 1;
  for (int64_t n = 2; n <= N; n++) {
    priority_queue<int64_t, vector<int64_t>, greater<int64_t>> tempq = d;
    while (!tempq.empty()) {
      int64_t tempd = tempq.top();
      if (tempd >= n) {
        break;
      }
      X[n] += X[n - tempd];
      if (X[n] > 998244353) {
        X[n] %= 998244353;
      }
      tempq.pop();
    }
  }
  int64_t output = (X[N] + 998244353) % 998244353;
  cout << output << endl;
  return 0;
}
