#include <bits/stdc++.h>
const int DIV = 998244353;
int max(int a, int b) {
  if (a >= b) {
    return (a);
  } else {
    return (b);
  }
}
int main(void) {
  int n;
  int k;
  int lr[10][2] = {0};
  int dp[200001] = {0};
  int sdp[200001] = {0};
  int i, j;
  scanf("%d%d", &n, &k);
  for (i = 0; i < k; i++) {
    scanf("%d%d", &lr[i][0], &lr[i][1]);
  }
  dp[1] = 1;
  sdp[2] = 1;
  for (i = 2; i <= n; i++) {
    for (j = 0; j < k; j++) {
      dp[i] +=
          (sdp[max(1, i - lr[j][0] + 1)] - sdp[max(1, i - lr[j][1])]) % DIV;
      dp[i] = dp[i] % DIV;
    }
    sdp[i + 1] += (sdp[i] + dp[i]) % DIV;
  }
  printf("%d\n", dp[n]);
  return (0);
}
