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