#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);
  vector<long long> L;
  for (int i = 0; i < K; ++i) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j < r + 1; ++j) L.push_back(j);
  }
  sort(L.begin(), L.end());
  C[0] = 1;
  for (int i = 1; i < N; ++i) {
    long long sum = 0;
    for (int j = 0; j < L.size(); ++j) {
      long long d = L[j];
      if (i - d >= 0) {
        sum += C[i - d];
        sum %= 998244353;
      } else {
        break;
      }
    }
    C[i] = sum;
  }
  cout << C[N - 1] << endl;
  ;
}
