#include <bits/stdc++.h>
int main() {
  int64_t N, K;
  std::cin >> N >> K;
  std::vector<std::pair<int64_t, int64_t>> LR;
  for (size_t k = 0; k < K; ++k) {
    int64_t L, R;
    std::cin >> L >> R;
    LR.emplace_back(L, R);
  }
  std::vector<int64_t> V;
  V.resize(2 * 100000, 0);
  V[0] = 1;
  for (int64_t i = 1; i < N; ++i) {
    for (auto& lr : LR) {
      for (int64_t j = lr.first; j <= lr.second && i - j >= 0; ++j) {
        V[i] += V[i - j];
      }
    }
  }
  std::cout << (V[N - 1] % 998244353) << std::endl;
  return 0;
}
