#include <bits/stdc++.h>
using namespace std;
using vec = vector<long long>;
long long facctorialMethod(long long k);
int main() {
  long long mod = 998244353;
  long long N, K;
  cin >> N >> K;
  vec L(K), R(K);
  vec dp(N, 0);
  for (long long i = 0; i < (K); i++) {
    cin >> L.at(i) >> R.at(i);
  }
  dp.at(0) = 1;
  for (long long x = 0; x < (N); x++)
    for (long long i = 0; i < (K); i++)
      for (long long j = L.at(i); j < (R.at(i) + 1); j++) {
        if (x + j < N) {
          dp.at(x + j) += dp.at(x);
          dp.at(x + j) %= mod;
        }
      }
  cout << dp.at(N - 1) << endl;
}
long long facctorialMethod(long long k) {
  long long sum = 1;
  for (long long i = 1; i <= k; ++i) {
    sum *= i;
  }
  return sum;
}
