#include <bits/stdc++.h>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
using namespace std;
template <typename T1, typename T2>
void ckmin(T1 &a, T2 b) {
  if (a > b) a = b;
}
template <typename T1, typename T2>
void ckmax(T1 &a, T2 b) {
  if (a < b) a = b;
}
template <typename T>
T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
int read() {
  int x = 0, f = 0;
  char ch = getchar();
  while (!isdigit(ch)) f |= ch == '-', ch = getchar();
  while (isdigit(ch)) x = 10 * x + ch - '0', ch = getchar();
  return f ? -x : x;
}
const int N = 500005;
const int mod = 998244353;
int l[N], r[N];
int dp[N], n, k;
int sum[N];
int main() {
  n = read(), k = read();
  for (int i = 1; i <= k; i++) {
    l[i] = read(), r[i] = read();
  }
  dp[1] = 1, sum[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 1; j <= k; j++) {
      int L = i - r[j], R = i - l[j];
      if (R < 0) continue;
      if (L <= 0) {
        dp[i] = (dp[i] + sum[R]) % mod;
      } else {
        dp[i] = (dp[i] + sum[R] - sum[L - 1]) % mod;
      }
    }
    sum[i] = (sum[i - 1] + dp[i]) % mod;
  }
  printf("%d\n", dp[n]);
  return 0;
}
