#include <bits/stdc++.h>
int max(int a, int b) {
  if (a > b)
    return a;
  else
    return b;
}
int min(int a, int b) {
  if (a < b)
    return a;
  else
    return b;
}
int compare_int(const void *a, const void *b) { return *(int *)a - *(int *)b; }
int main() {
  long long N, K;
  scanf("%lld %lld", &N, &K);
  long long L[12], R[12];
  long long num[20002] = {0};
  for (long long i = 1; i <= K; i++) {
    scanf("%lld %lld", L + i, R + i);
    for (long long j = L[i]; j <= R[i]; j++) {
      num[j] = 1;
    }
  }
  long long step[20002], step_num = 0;
  for (long long i = 1; i < 20002; i++) {
    if (num[i] == 1) step[step_num++] = i;
  }
  long long DP[20002] = {0};
  DP[1] = 1;
  for (long long i = 2; i <= N; i++) {
    long long j = 0;
    while (i - step[j] >= 1 && j < step_num) {
      DP[i] += DP[i - step[j]];
      DP[i] %= 998244353;
      j++;
    }
  }
  printf("%lld", DP[N]);
}
