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