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