#include <bits/stdc++.h>
using namespace std;
const int MAX = 2e5;
const int MOD = 998244353;
int main() {
  int N, K;
  cin >> N >> K;
  int L[10], R[10];
  for (int i = 0; i < K; i++) {
    cin >> L[i] >> R[i];
  }
  long long dp[MAX];
  dp[0] = 1;
  dp[1] = MOD - 1;
  long long num = 0;
  for (int i = 0; i < N; i++) {
    num = (num + dp[i]) % MOD;
    if (num == 0) continue;
    for (int j = 0; j < K; j++) {
      if (i + L[j] < N) dp[i + L[j]] = (dp[i + L[j]] + num) % MOD;
      if (i + R[j] + 1 < N)
        dp[i + R[j] + 1] = (dp[i + R[j] + 1] - num + MOD) % MOD;
    }
  }
  for (int i = 0; i < N - 1; i++) {
    dp[i + 1] = (dp[i] + dp[i + 1]) % MOD;
  }
  cout << num << endl;
}
