#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  long long N, K;
  cin >> N >> K;
  vector<long long> C(N + 1);
  vector<long long> S(N + 1);
  vector<long long> L;
  vector<long long> R;
  for (long long i = 0; i < K; ++i) {
    long long l, r;
    cin >> l >> r;
    L.push_back(l);
    R.push_back(r);
  }
  sort(L.begin(), L.end());
  C[0] = 0;
  C[1] = 1;
  S[0] = 0;
  S[1] = 1;
  for (long long i = 2; i < N + 1; ++i) {
    long long sum = 0;
    for (long long j = 0; j < L.size(); ++j) {
      long long d1 = L[j];
      long long d2 = R[j] + 1;
      long long r1 = i - d1;
      long long r2 = i - d2;
      if (r1 < 0) r1 = 0;
      if (r2 < 0) r2 = 0;
      sum += S[r1] - S[r2];
    }
    C[i] = sum;
    C[i] %= 998244353;
    S[i] = S[i - 1] + sum;
  }
  cout << C[N] << endl;
  ;
}
