#include <bits/stdc++.h>
int n, k, m;
int a[200001], f[200001];
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;
    }
  }
  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;
      }
    }
  }
  printf("%d\n", f[n]);
  return 0;
}
