#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N, K, L, R;
  cin >> N >> K;
  vector<long long> steps;
  vector<long long> dp(N, 0);
  for (long long i = 0; i < K; i++) {
    cin >> L >> R;
    for (long long j = L; j <= R; j++) {
      steps.push_back(j);
    }
  }
  dp[0] = 1;
  for (long long i = 0; i < N; i++) {
    for (auto step : steps) {
      if (i + step < N) dp[i + step] = (dp[i + step] + dp[i]) % 998244353;
    }
  }
  cout << dp[N - 1] << endl;
}
