#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long s = 0, w = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
  return s * w;
}
inline bool read(long long& a) {
  long long s = 0, w = 1;
  char ch = getchar();
  if (ch == EOF) {
    return false;
  }
  while (ch < '0' || ch > '9') {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
  a = s * w;
  return true;
}
inline void write(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
inline void writeln(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
  puts("");
}
const long long mod = 998244353;
long long l[20], r[20];
set<long long> s;
long long dp[200010];
long long a[200010];
signed main() {
  long long n, k;
  read(n), read(k);
  for (long long i = 1; i <= k; i++) {
    read(l[i]), read(r[i]);
    for (long long j = l[i]; j <= r[i]; j++) s.insert(j);
  }
  long long cnt = 0;
  for (set<long long>::iterator it = s.begin(); it != s.end(); it++)
    a[++cnt] = *it;
  dp[1] = 1;
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; a[j] <= i, j <= cnt; j++)
      if (dp[i - a[j]] > 0 && i - a[j] >= 0)
        dp[i] = (dp[i] + dp[i - a[j]]) % mod;
  }
  writeln(dp[n] % mod);
  return 0;
}
