#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 10, mod = 998244353;
long long S[N], cnt, dp[N];
long long n, k;
inline long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + (ch ^ 48);
    ch = getchar();
  }
  return x * f;
}
long long cell(long long x) {
  if (x <= 0) return 0;
  for (long long i = 1; i <= cnt; i++)
    if (x == S[i]) return x;
  long long ans = 0;
  for (long long i = 1; i <= cnt; i++) ans = (ans + cell(x - S[i])) % mod;
  cout << ans << endl;
  return ans;
}
signed main() {
  n = read();
  k = read();
  for (long long i = 1, l, r; i <= k; i++) {
    l = read();
    r = read();
    for (long long j = l; j <= r; j++) S[++cnt] = j;
  }
  sort(S + 1, S + cnt + 1);
  for (long long i = 1; i <= cnt; i++) dp[S[i]]++;
  for (long long i = 1; i <= n - 1; i++)
    for (long long j = 1; j <= cnt; j++) {
      if (i >= S[j]) dp[i] = (dp[i] + dp[i - S[j]]) % mod;
    }
  printf("%lld\n", dp[n - 1]);
  return 0;
}
