#include <iostream>

typedef long long ll;

const ll MOD = 998244353;

ll N, K, dp[200005], dps[200005];
int S[11][3];

ll sum(ll l, ll r) {
  if (r < 1)  return 0;
  ll ans = dps[r];
  if (l > 1) ans = (ans - dps[l-1] + MOD) % MOD;
  return ans;
}

int main() {
  std::cin >> N >> K;
  for (int i = 0; i < K; ++i)
    std::cin >> S[i][0] >> S[i][1];

  dps[0] = 0;
  dp[1] = 1, dps[1] = 1;
  for (int i = 2; i <= N; ++i) {
    dp[i] = 0;
    for (int k = 0; k < K; ++k)
      dp[i] = (dp[i] + sum(i - S[k][1], i - S[k][0])) % MOD;
    dps[i] = (dp[i] + dps[i-1]) % MOD;
  }

  std::cout << dp[N] << "\n";

  return 0;
}
