#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
void Main() {
  long long N, K;
  cin >> N >> K;
  vector<long long> L(K, 0), R(K, 0);
  for (int i = 0; i < K; ++i) {
    cin >> L[i] >> R[i];
  }
  vector<long long> ans(N, 0);
  ans[0] = 1;
  for (long long i = 0; i < N; ++i) {
    for (long long k = 0; k < K; ++k) {
      for (long long j = L[k]; j <= R[k]; ++j) {
        long long n = i + j;
        if (i < n && n < N) {
          ans[n] += ans[i];
          ans[n] %= MOD;
        }
      }
    }
  }
  cout << ans[N - 1] << endl;
}
int main() {
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}
