#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
  return b ? gcd(b, a % b) : a;
}
long long int lcm(long long int a, long long int b) {
  return a / gcd(a, b) * b;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
const long long int MOD = 998244353;
const long long int INF = 1e18;
const long double PI = (acos(-1));
struct mint {
  long long int x;
  mint(long long int x = 0) : x((x % MOD + MOD) % MOD) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD - a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= MOD;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(long long int t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }
  mint inv() const { return pow(MOD - 2); }
  mint& operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};
ostream& operator<<(ostream& os, const mint& m) {
  os << m.x;
  return os;
}
signed main() {
  long long int N, K;
  cin >> N >> K;
  set<long long int> se;
  for (long long int i = 0; i < (long long int)(K); i++) {
    long long int l, r;
    cin >> l >> r;
    for (long long int j = l; j <= r; j++) se.insert(j);
  }
  vector<mint> dp(N, 0);
  dp[N - 1] = 1;
  for (long long int i = N - 2; i >= 0; i--) {
    for (auto j : se) {
      if (i + j >= N) break;
      dp[i] += dp[i + j];
    }
  }
  cout << dp[0];
}
