#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using P = pair<int, int>;
const LL mod = 998244353;
int main() {
  LL N, K;
  cin >> N >> K;
  vector<LL> L(K), R(K);
  for (int i = 0; i < (int)(K); i++) cin >> L[i] >> R[i];
  vector<LL> dp(N + 1), num(K);
  dp[1] = 1;
  for (int i = 2; i <= N; i++) {
    for (int j = 0; j < (int)(K); j++) {
      if (R[j] < i) {
        num[j] += dp[i - L[j]];
        num[j] -= dp[i - R[j] - 1];
        dp[i] += num[j];
      } else if (L[j] < i) {
        num[j] += dp[i - L[j]];
        for (int k = 1; k <= i - L[j]; k++) dp[i] += dp[k];
      }
      dp[i] %= mod;
    }
  }
  LL ans = dp[N];
  while (ans < 0) ans += mod;
  cout << ans << endl;
  return 0;
}
