#include <bits/stdc++.h>
int main(void) {
  int N, K, k, n, m;
  int L, R;
  int flg[200000 + 1] = {0};
  int S[200000 + 1] = {0};
  std::cin >> N >> K;
  for (k = 1; k <= K; k++) {
    std::cin >> L >> R;
    for (n = L; n <= R; n++) {
      flg[n] = 1;
    }
  }
  S[1] = 1;
  for (n = 2; n <= N; n++) {
    for (m = 1; m < n; m++) {
      if (flg[m]) {
        S[n] += S[n - m];
        S[n] %= 998244353;
      }
    }
  }
  std::cout << S[N] << std::endl;
  return 0;
}
