#include <bits/stdc++.h>
int main() {
  int N, K;
  std::cin >> N >> K;
  std::vector<int> S;
  S.reserve(N);
  for (int i = 0; i < K; ++i) {
    int L, R;
    std::cin >> L >> R;
    for (int j = L; j <= R; ++j) {
      S.push_back(j);
    }
  }
  std::sort(S.begin(), S.end());
  std::vector<int64_t> memo(N + 1);
  memo[N] = 1;
  for (int pos = N - 1; pos >= 1; --pos) {
    int64_t count = 0;
    for (auto itr = S.begin(); itr != S.end(); ++itr) {
      const int pos_move = pos + *itr;
      if (pos_move > N) {
        break;
      }
      count += memo[pos_move];
    }
    memo[pos] = count % 998244353;
  }
  std::cout << memo[1] << std::endl;
  return 0;
}
