#include <bits/stdc++.h>
using namespace std;
;
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;
  dp[1] = -1;
  for (int i = 0; i < N; i++) {
    dp[i] = ((dp[i] % 998244353) + 998244353) % 998244353;
    dp[i + 1] = (dp[i + 1] + dp[i]) % 998244353;
    for (int j = 0; j < K; j++) {
      dp[i + L[j]] += dp[i];
      dp[i + R[j] + 1] -= dp[i];
    }
  }
  cout << dp[N - 1] << endl;
}
