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