#include <bits/stdc++.h>
using namespace std;
long long L[11], R[11];
long long dp[100005];
long long sum[100005];
signed main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  long long N, K;
  cin >> N >> K;
  for (long long i = 1; i <= K; i++) {
    cin >> L[i] >> R[i];
  }
  sum[1] = dp[1] = 1;
  for (long long i = 2; i <= N; i++) {
    for (long long j = 1; j <= K; j++) {
      if (i - L[j] < 1)
        continue;
      else if (i - R[j] < 1) {
        dp[i] = (dp[i] + sum[i - L[j]]) % 998244353;
      } else {
        dp[i] = (dp[i] + sum[i - L[j]]) % 998244353;
        dp[i] = (dp[i] - sum[i - R[j] - 1] + 998244353) % 998244353;
      }
    }
    sum[i] = (sum[i - 1] + dp[i]) % 998244353;
  }
  cout << dp[N] << endl;
}
