#include <bits/stdc++.h>
using namespace std;
int main() {
  long long mod = 998244353;
  bool w[200002];
  long long d[200002];
  for (int i = 0; i < 200002; i++) {
    d[i] = 0;
    w[i] = 0;
  }
  int n, k;
  scanf("%d %d", &n, &k);
  for (int i = 0; i < k; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    for (int j = a; j <= b; j++) w[j] = 1;
  }
  d[0] = 1;
  for (int i = 0; i < n; i++) {
    if (d[i] == 0) continue;
    for (int j = 1; j <= n; j++) {
      if (w[j] && i + j <= n) {
        d[i + j] += d[i];
        d[i + j] %= mod;
      }
    }
  }
  printf("%lld\n", d[n - 1]);
  return 0;
}
