#include <bits/stdc++.h>
int main(void) {
  int n, k;
  scanf("%d%d", &n, &k);
  int s[200001] = {0};
  for (int i = 0; i < k; i++) {
    int left, right;
    scanf("%d%d", &left, &right);
    for (int i = left; i <= right; i++) {
      s[i] = 1;
    }
  }
  int count = 0;
  for (int i = 1; i <= n; i++) {
    if (s[i]) {
      s[count++] = i;
      s[i] = 0;
    }
  }
  int dp[200001] = {0, 1};
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < count; j++) {
      int next = i + s[j];
      if (next > n) {
        break;
      }
      dp[next] += dp[i];
      dp[next] %= 998244353;
    }
  }
  printf("%d\n", dp[n] % 998244353);
  return 0;
}
