#include <bits/stdc++.h>
using namespace std;
int L[10], R[10];
int cache[200009];
int f(int N, int K) {
  int ans = 0;
  if (cache[N] != -1) {
    return cache[N];
  }
  for (int i = 0; i < K && L[i] <= N; ++i) {
    for (int j = L[i]; j <= R[i] && j <= N; j++) {
      ans += f(N - j, K);
      ans %= 998244353;
    }
  }
  cache[N] = ans;
  return ans;
}
int main() {
  int N, K;
  scanf("%d%d", &N, &K);
  for (int i = 0; i < K; ++i) {
    scanf("%d%d", L + i, R + i);
  }
  for (int i = 0; i < 200009; i++) {
    cache[i] = -1;
  }
  cache[0] = 1;
  sort(L, L + K);
  sort(R, R + K);
  printf("%d\n", f(N - 1, K));
}
