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