#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long N, K;
  cin >> N >> K;
  vector<long long> L(K), R(K);
  map<long long, long long> S, ans;
  for (long long i = 0; i < K; i++) {
    cin >> L.at(i) >> R.at(i);
  }
  long long mod = 998244353;
  for (long long i = 1; i <= N; i++) {
    for (long long j = 0; j < K; j++) {
      if (i >= L.at(j) && i <= R.at(j)) {
        S[i] = 1;
      }
    }
  }
  for (long long j = 1; j <= N; j++) {
    if (S[j]) {
      if (1 + j <= N) {
        ans[1 + j] = 1;
      }
    }
  }
  for (long long i = 2; i <= N; i++) {
    for (long long j = 1; j <= N; j++) {
      if (S[j]) {
        if (i + j <= N) {
          ans[i + j] += ans[i];
          ans[i + j] %= mod;
        }
      }
    }
  }
  cout << ans[N];
}
