#include <bits/stdc++.h>
int main() {
  const std::size_t mod = 998244353;
  std::size_t N, K;
  std::cin >> N >> K;
  std::vector<std::size_t> select;
  for (std::size_t index = 0; index < K; ++index) {
    std::size_t l, r;
    std::cin >> l >> r;
    for (std::size_t num = l; num <= r; ++num) {
      select.push_back(num);
    }
  }
  std::sort(select.begin(), select.end());
  std::vector<bool> num_exist(N, false);
  for (auto S : select) {
    num_exist[S - 1] = true;
  }
  std::vector<std::size_t> dp(N, 0);
  dp[0] = 1;
  for (std::size_t num = 2; num <= N; ++num) {
    for (std::size_t prev = 1; prev < num; ++prev) {
      if (num_exist[num - prev - 1]) {
        dp[num - 1] += dp[prev - 1] % mod;
      }
    }
  }
  std::cout << dp[N - 1] % mod << std::endl;
  return 0;
}
