#include <bits/stdc++.h>
using namespace std;
using u64 = uint64_t;
static u64 counter[200001];
int main() {
  int N, K;
  std::vector<int> s;
  cin >> N >> K;
  for (int i = 0; i < K; i++) {
    int L, R;
    cin >> L >> R;
    for (int i = 0; i <= R - L; i++) {
      s.push_back(L + i);
    }
  }
  counter[N] = 1;
  for (int i = N; i != 0; i--) {
    u64 current = counter[i];
    for (auto si : s) {
      if (i > si) {
        counter[i - si] += current;
      }
    }
  }
  cout << counter[1] % 998244353U << endl;
  return 0;
}
