#include <bits/stdc++.h>
using namespace std;
int n, k;
long long l[200001], r[200001], f[200001], s[200001];
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= k; i++) {
    scanf("%lld %lld", &l[i], &r[i]);
  }
  f[1] = 1;
  s[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 1; j <= k; j++) {
      f[i] = f[i] + s[max(i - l[j], (long long)0)] -
             s[max(i - r[j] - 1, (long long)0)];
    }
    s[i] = s[i - 1] + f[i];
  }
  printf("%lld\n", f[n] % 998244353);
  return 0;
}
