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