#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;
int main() {
  int N;
  cin >> N;
  int K;
  cin >> K;
  const int MOD = 998244353;
  vector<int> step;
  for (int i = 0; i < (K); ++i) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++) {
      step.emplace_back(j);
    }
  }
  vector<long long> way(N + 1, 0);
  way[1] = 1;
  for (int i = 1; i < N; i++) {
    for (const auto &s : step) {
      if (i + s <= N) {
        way[i + s] += way[i];
        way[i + s] %= MOD;
      }
    }
  }
  cout << way[N] << endl;
  return 0;
}
