#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  bool b[200001] = {0};
  int k, n, l, r;
  long long int d[200001] = {0};
  cin >> n >> k;
  long long int z;
  while (k--) {
    cin >> l >> r;
    for (int i = l; i <= r; i++) b[i] = 1;
  }
  d[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 1; j < i; j++) {
      if (b[i - j]) {
        d[i] = (d[j] + d[i]) % 998244353;
      }
    }
  }
  cout << d[n] << endl;
  return 0;
}
