#include <bits/stdc++.h>
using namespace std;
vector<int> S(200000), npos(200000, -1);
int N, Ns;
long long Numbun(int pos) {
  if (npos[pos - 1] != -1) return npos[pos - 1];
  if (pos == N) return 1;
  long long Sum = 0;
  for (int i = 0; i < Ns; i++) {
    if (pos + S[i] <= N) {
      Sum += Numbun(pos + S[i]);
    }
  }
  return npos[pos - 1] = Sum % 998244353;
}
int main() {
  int K, i, j, k = 0, L, R;
  long long Sum;
  cin >> N >> K;
  for (i = 0; i < K; i++) {
    cin >> L >> R;
    for (j = L; j <= R; j++) {
      S[k] = j;
      k++;
    }
  }
  Ns = k;
  S.resize(k);
  npos.resize(N);
  cout << Numbun(1) << endl;
  return 0;
}
