#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<long long, long long>;
const long double pi = acos(-1.0);
const long long MAX = 1000010;
const long long INF = 1ll << 60;
const long long MOD = 998244353;
template <typename T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T>
inline bool chmin(T& a, T b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
inline void print(P a) { cout << a.first << " " << a.second << endl; }
template <typename T>
T pow(T a, ll n) {
  T r(1);
  while (n) {
    if (n & 1) r *= a;
    a *= a;
    n >>= 1;
  }
  return r;
}
struct faster_io {
  faster_io() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
  }
} faster_io_;
template <long long mod>
struct ModInt {
  long long x;
  ModInt() : x(0) {}
  ModInt(long long x_) {
    if ((x = x_ % mod + mod) >= mod) x -= mod;
  }
  ModInt inv() const { return pow(*this, mod - 2); }
  ModInt& operator+=(ModInt rhs) {
    if ((x += rhs.x) >= mod) x -= mod;
    return *this;
  }
  ModInt& operator-=(ModInt rhs) {
    if ((x -= rhs.x) < 0) x += mod;
    return *this;
  }
  ModInt& operator*=(ModInt rhs) {
    x = (unsigned long long)x * rhs.x % mod;
    return *this;
  }
  ModInt& operator/=(ModInt rhs) {
    x = (unsigned long long)x * rhs.inv().x % mod;
    return *this;
  }
  ModInt operator-() const { return -x < 0 ? mod - x : -x; }
  ModInt operator+(ModInt rhs) const { return ModInt(*this) += rhs; }
  ModInt operator-(ModInt rhs) const { return ModInt(*this) -= rhs; }
  ModInt operator*(ModInt rhs) const { return ModInt(*this) *= rhs; }
  ModInt operator/(ModInt rhs) const { return ModInt(*this) /= rhs; }
  bool operator==(ModInt rhs) const { return x == rhs.x; }
  bool operator!=(ModInt rhs) const { return x != rhs.x; }
  friend ostream& operator<<(ostream& s, ModInt<mod> a) {
    s << a.x;
    return s;
  }
  friend istream& operator>>(istream& s, ModInt<mod>& a) {
    s >> a.x;
    return s;
  }
};
using mint = ModInt<MOD>;
long long ms[MAX];
mint dp[MAX];
signed main() {
  long long n, k;
  cin >> n >> k;
  for (long long i = 0; i < (long long)(k); i++) {
    long long l, r;
    cin >> l >> r;
    ms[l]++;
    ms[r + 1]--;
  }
  vector<long long> v;
  for (long long i = (1); i < (long long)(n); i++) {
    ms[i] += ms[i - 1];
    if (ms[i] == 1) v.push_back(i);
  }
  dp[1] = 1;
  for (long long i = (1); i < (long long)(n + 1); i++) {
    for (auto j : v) {
      if (i + j > n) break;
      if (ms[j] == 1) dp[i + j] += dp[i];
    }
  }
  cout << dp[n] << endl;
  return 0;
}
