#include <bits/stdc++.h>
using namespace std;
int main() {
  int mod = 998244353;
  long long N, K;
  cin >> N >> K;
  vector<pair<long long, long long>> intervals(K);
  for (int i = 0; i < K; i++) {
    cin >> intervals[i].first >> intervals[i].second;
  }
  sort(intervals.begin(), intervals.end());
  vector<long long> dp(N + 1);
  dp[1] = 1;
  for (long long i = 1; i < N; i++) {
    bool is_too_large = false;
    if (dp[i] == 0) continue;
    for (int k = 0; k < K; k++) {
      for (long long step = intervals[k].first; step <= intervals[k].second;
           step++) {
        if (i + step > N) {
          is_too_large = true;
          break;
        } else {
          dp[i + step] += dp[i];
          dp[i + step] %= mod;
        }
      }
      if (is_too_large == true) break;
    }
  }
  cout << dp[N];
  return 0;
}
