#include <bits/stdc++.h>
using namespace std;
const long long int INF = 998244353;
int main(void) {
  long long N, K;
  cin >> N >> K;
  vector<long long> s;
  for (long long i = 0; i < K; i++) {
    long long L, R;
    cin >> L >> R;
    for (long long j = L; j <= R; j++) {
      s.push_back(j);
    }
  }
  long long W = s.size();
  sort(s.begin(), s.end());
  vector<long long> v(N, 0);
  v[0] = 1;
  for (long long i = 0; i < N; i++) {
    for (long long j = 0; j < W; j++) {
      long long next = i + s[j];
      if (next > N - 1) break;
      v[next] += v[i];
      v[next] %= INF;
    }
  }
  cout << v[N - 1] << endl;
}
