#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
int main() {
  int N, K;
  cin >> N >> K;
  vector<int> L(K), R(K);
  for (int i = 0; i < K; i++) {
    cin >> L[i] >> R[i];
  }
  vector<long long> dp(N + 1, 0);
  dp[0] = 1;
  for (int i = 0; i < N - 1; i++) {
    if (i != 0) dp[i] += dp[i - 1];
    dp[i] = (dp[i] + MOD) % MOD;
    for (int k = 0; k < K; k++) {
      if (i + L[k] <= N - 1) {
        dp[i + L[k]] += dp[i];
        dp[i + L[k]] = (dp[i + L[k]] + MOD) % MOD;
      }
      if (i + R[k] + 1 <= N - 1) dp[i + R[k] + 1] -= dp[i];
      dp[i + R[k] + 1] = (dp[i + R[k] + 1] + MOD) % MOD;
    }
  }
  cout << (dp[N - 1] + MOD) % MOD << endl;
  return 0;
}
