#include <bits/stdc++.h>
using namespace std;
long long N, K;
long long L[11], R[11];
long long dp[200010];
long long mod = 998244353;
signed main() {
  cin >> N >> K;
  for (long long i = 0; i < K; i++) cin >> L[i] >> R[i];
  dp[1] = 1;
  for (long long i = 2; i <= N; i++) {
    long long diff = 0;
    for (long long j = 0; j < K; j++) {
      diff =
          (diff + dp[max(0LL, i - L[j])] - dp[max(0LL, i - R[j] - 1)] + mod) %
          mod;
    }
    dp[i] = (dp[i - 1] + diff) % mod;
  }
  cout << (dp[N] - dp[N - 1]) % mod << endl;
  return 0;
}
