#include <bits/stdc++.h>
using namespace std;
const int P = 139;
const int mod = 998244353;
const int maxn = 1e6 + 5;
const int inf = 0x3f3f3f3f;
const int minn = 0xc0c0c0c0;
int k, n, l[maxn], r[maxn], dp[maxn], sum[maxn];
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= k; i++) scanf("%d%d", &l[i], &r[i]);
  dp[1] = 1;
  sum[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 1; j <= k; j++)
      dp[i] = (dp[i] + sum[max(0, i - l[j])] - sum[max(0, i - r[j] - 1)]) % mod;
    sum[i] = (sum[i - 1] + dp[i]) % mod;
  }
  printf("%d\n", (dp[n] + mod) % mod);
  return 0;
}
