#include <bits/stdc++.h>
int n, k, m;
int a[200001], f[200001];
void qsort(int, int);
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= k; i++) {
    int l, r;
    scanf("%d %d", &l, &r);
    for (int j = l; j <= r; j++) {
      a[++m] = j;
    }
  }
  qsort(1, m);
  f[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (a[j] < i) {
        f[i] = (f[i] + f[i - a[j]]) % 998244353;
      } else {
        break;
      }
    }
  }
  printf("%d\n", f[n]);
  return 0;
}
void qsort(int l, int r) {
  int i = l, j = r, mid = (i + j) / 2;
  do {
    while (a[i] < a[mid]) i++;
    while (a[j] > a[mid]) j--;
    if (i <= j) {
      int tmp = a[i];
      a[i] = a[j];
      a[j] = tmp;
      i++, j--;
    }
  } while (i <= j);
  if (l < j) qsort(l, j);
  if (i < r) qsort(i, r);
}
