#include <iostream>
#include <set>

#define N_MAX (2*100000)
#define MOD (998244353)

unsigned int dp[N_MAX];

int main() {
  int N, K;
  std::cin >> N >> K;

  int L[10], R[10];
  for (int i = 0; i < K; i++) {
    std::cin >> L[i] >> R[i];
  }
  dp[0] = 1;
  for (int i = 1; i < N; i++) {
    dp[i] = dp[i-1];
    for (int k = 0; k < K; k++) {
      if (i-L[k] >= 0 && i-R[k]-1 >= 0) {
        dp[i] += (MOD + dp[i-L[k]] - dp[i-R[k]-1]) % MOD;
      } else if (i-L[k] >= 0) {
        dp[i] += dp[i-L[k]];
      }
      dp[i] %= MOD;
    }
  }
  std::cout << (MOD + dp[N-1] - dp[N-2]) % MOD << std::endl;
  return 0;
}
