#include <bits/stdc++.h>
int main(void) {
  long long n, k, m, i, j, tmp, mod = 998244353;
  scanf("%lld %lld", &n, &k);
  long long le[k], ri[k], cou[n];
  for (i = 0; i < k; i++) {
    scanf("%lld %lld", &le[i], &ri[i]);
  }
  for (i = 0; i < n; i++) cou[i] = 0;
  cou[0] = 1;
  for (i = 0; i < n; i++) {
    for (j = 0; j < k; j++) {
      for (m = le[j]; m <= ri[j]; m++) {
        if (i + m < n) {
          cou[i + m] = (cou[i + m] + cou[i]) % mod;
        }
      }
    }
  }
  printf("%lld", cou[n - 1]);
  return 0;
}
