#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, li, ri;
  cin >> N >> K;
  vec L(K), R(K);
  vec dp(N, 0), dpsum(N, 0);
  for (long long i = 0; i < (K); i++) {
    cin >> L.at(i) >> R.at(i);
  }
  dp.at(0) = 1;
  dpsum.at(0) = 1;
  for (long long x = 1; x < (N); x++) {
    for (long long i = 0; i < (K); i++) {
      li = x - R.at(i);
      ri = x - L.at(i);
      if (ri < 0) continue;
      li = max(li, (long long)1);
      dp.at(x) += dpsum.at(ri) - dpsum.at(li - 1);
      dp.at(x) %= mod;
    }
    dpsum.at(x) = dpsum.at(x - 1) + dp.at(x);
    dpsum.at(x) %= 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;
}
