#include <bits/stdc++.h>
const long long MOD = 998244353;
long long N, K, dp[200005];
int S[11][3];
long long solve(int i) {
  if (i > N) return 0;
  if (i == N) return 1;
  if (dp[i] != -1) return dp[i];
  long long ans = 0;
  for (int k = 0; k < K; ++k)
    for (int d = S[k][0]; d <= S[k][1]; ++d) ans = (ans + solve(i + d)) % MOD;
  return dp[i] = ans;
}
int main() {
  std::cin >> N >> K;
  for (int i = 0; i < K; ++i) std::cin >> S[i][0] >> S[i][1];
  for (int i = 0; i < 200005; ++i) dp[i] = -1;
  std::cout << solve(1) << "\n";
  return 0;
}
