#include <bits/stdc++.h>
using namespace std;
const long long maxS = 2e5 + 10;
long long MOD = 998244353;
long long DP[2 * maxS];
void code_idhr_h() {
  long long N, K;
  cin >> N >> K;
  vector<long long> L(K + 1), R(K + 1);
  for (long long i = 1; i <= K; i++) cin >> L[i] >> R[i];
  DP[1] = 1;
  for (long long i = 1; i <= N; i++) {
    for (long long j = 1; j <= K; j++) {
      DP[i + L[j]] = (DP[i + L[j]] + DP[i]) % MOD;
      DP[i + R[j] + 1] = (DP[i + R[j] + 1] - DP[i] + MOD) % MOD;
    }
    DP[i + 1] = (DP[i + 1] + DP[i]) % MOD;
  }
  cout << (DP[N] - DP[N - 1]) % MOD;
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long T = 1;
  for (long long t = 1; t <= T; t++) {
    code_idhr_h();
  }
  return 0;
}
