#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N;
  long long K;
  cin >> N >> K;
  long long L[K];
  long long R[K];
  for (int i = 0; i < K; i++) {
    cin >> L[i] >> R[i];
  }
  vector<long long> dp(N + 1, 0);
  vector<long long> acc_sum(N + 1, 0);
  dp[1] = 1;
  acc_sum[1] = 1;
  for (int i = 2; i <= N; ++i) {
    for (int j = 0; j < K; j++) {
      int rj = i - L[j];
      int lj = i - R[j];
      if (rj < 0) continue;
      lj = max(lj, 1);
      dp[i] += (acc_sum[rj] - acc_sum[lj - 1]) % 998244353;
      dp[i] %= 998244353;
    }
    acc_sum[i] = (acc_sum[i - 1] + dp[i]) % 998244353;
  }
  cout << dp[N] << endl;
  return 0;
}
