#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O2")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse3", "sse2", "sse")
#pragma GCC optimize("inline", "fast-math", "unroll-loops", \
                     "no-stack-protector")
class complex {
 public:
  inline char gc() {
    static const signed IN_LEN = 1 << 18 | 1;
    static char buf[IN_LEN], *s, *t;
    return (s == t) && (t = (s = buf) + fread(buf, 1, IN_LEN, stdin)),
           s == t ? -1 : *s++;
  }
  template <typename _Tp>
  inline complex& operator>>(_Tp& x) {
    static char ch, sgn;
    ch = gc(), sgn = 0;
    for (; !isdigit(ch); ch = gc()) {
      if (ch == -1) return *this;
      sgn |= ch == '-';
    }
    for (x = 0; isdigit(ch); ch = gc()) x = x * 10 + (ch ^ '0');
    sgn && (x = -x);
    return *this;
  }
} inc;
long long n, k;
long long dp[200005];
long long stp[200005];
long long idx = 0;
signed main() {
  inc >> n >> k;
  register long long i, j;
  for (i = 1; i <= k; ++i) {
    long long x, y;
    inc >> x >> y;
    for (j = x; j <= y; ++j) stp[++idx] = j;
  }
  dp[1] = 1;
  for (i = 2; i <= n / 4; ++i) {
    for (j = 1; j <= idx; ++j) {
      if (i - stp[j] >= 1) dp[i] = (dp[i] + dp[i - stp[j]]) % 998244353;
    }
  }
  for (; i <= n / 2; ++i) {
    for (j = 1; j <= idx; ++j) {
      if (i - stp[j] >= 1) dp[i] = (dp[i] + dp[i - stp[j]]) % 998244353;
    }
  }
  for (; i <= n; ++i) {
    for (j = 1; j <= idx; ++j) {
      if (i - stp[j] >= 1) dp[i] = (dp[i] + dp[i - stp[j]]) % 998244353;
    }
  }
  printf("%lld\n", dp[n]);
  return 0;
}
