#include <bits/stdc++.h>
using namespace std;
const long long M = 998244353;
int main() {
  long long N, K;
  cin >> N >> K;
  long long L[K], R[K];
  vector<long long> p;
  for (long long i = 0; i < K; i++) {
    cin >> L[i] >> R[i];
    for (long long j = L[i]; j <= R[i]; j++) {
      p.push_back(j);
    }
  }
  sort(p.begin(), p.end());
  long long m[N + 1];
  long long ans = 0;
  m[1] = 1;
  for (long long num = 2; num < N + 1; num++) {
    m[num] = 0;
    bool ok = false;
    for (long long i = 0; i < p.size(); i++) {
      if (p[i] <= num - 1) {
        m[num] += m[num - p[i]] % M;
        m[num] = m[num] % M;
      } else {
        break;
      }
    }
  }
  cout << m[N] << endl;
}
