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