#include <bits/stdc++.h>
int main(int argc, char const* argv[]) {
  int mod = 998244353;
  int n, k;
  scanf("%d %d", &n, &k);
  int flags[n + 1];
  for (int i = 0; i <= n; i++) flags[i] = 0;
  for (int i = 0; i < k; i++) {
    int l, r;
    scanf("%d %d", &l, &r);
    for (int j = l; j <= r; j++) {
      flags[j] = 1;
    }
  }
  int set[n];
  int length = 0;
  for (int i = 1; i <= n; i++) {
    if (flags[i]) set[length++] = i;
  }
  int dp[n];
  dp[0] = 1;
  for (int i = 1; i < n; i++) {
    dp[i] = 0;
    for (int j = 0; j < length && i - set[j] >= 0; j++) {
      dp[i] = (dp[i] + dp[i - set[j]]) % mod;
    }
  }
  printf("%d\n", dp[n - 1]);
  return 0;
}
