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