#include <bits/stdc++.h>
long a[200001];
int s[200001], d[200001];
long ans(int n) {
  long t;
  int j;
  if (a[n] >= 0) return a[n];
  t = 0;
  for (j = 1; j < n; j += d[n - j])
    if (s[n - j]) t = (t + ans(j)) % 998244353;
  a[n] = t;
  return t;
}
int main() {
  int i, j, k, n, l, r;
  scanf("%d %d", &n, &k);
  for (i = 1; i <= n; i++) {
    s[i] = 0;
    a[i] = -1;
  }
  for (i = 0; i < k; i++) {
    scanf("%d %d", &l, &r);
    for (j = l; j <= r; j++) s[j] = 1;
  }
  for (j = n; j > 0 && !s[j]; j--)
    ;
  for (i = n; i > 0; i--) {
    if (i <= j)
      for (j = i - 1; j > 0 && !s[j]; j--)
        ;
    d[i] = i - j;
  }
  a[1] = 1;
  printf("%ld\n", ans(n));
  return 0;
}
