#include <bits/stdc++.h>
using namespace std;
long long mod = 998244353;
long long Count(long long x, const vector<long long> &S,
                vector<long long> &count, vector<long long> &seen) {
  if (seen[x] == 1) {
    return count[x];
  }
  long long res = 0;
  for (long long i = 0; i < S.size(); i++) {
    if (x - S[i] - 1 > 0)
      res = (res + Count(x - S[i], S, count, seen)) % mod;
    else if (x - S[i] - 1 == 0) {
      res++;
    }
  }
  count[x] = res;
  seen[x] = 1;
  return res;
}
int main(void) {
  long long N, K;
  cin >> N >> K;
  vector<long long> L(K);
  vector<long long> R(K);
  for (long long i = 0; i < K; i++) {
    cin >> L[i] >> R[i];
  }
  vector<long long> seen(N + 1);
  for (long long i = 0; i < N + 1; i++) {
    seen[i] = 0;
  }
  vector<long long> count(N + 1);
  vector<long long> S;
  for (long long i = 0; i < K; i++) {
    for (long long j = 0; j <= R[i] - L[i]; j++) {
      S.push_back(L[i] + j);
    }
  }
  long long ans = Count(N, S, count, seen);
  cout << ans << endl;
}
