#include <bits/stdc++.h>
using namespace std;
using ll = long long;
inline constexpr ll Inf = (1ULL << 62) - 1;
template <class T>
bool updmax(T& a, T b) {
  if (b > a) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool updmin(T& a, T b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
T permutation(ll n, ll k) {
  T f(1);
  for (ll i = 0; i < k; ++i, --n) f *= n;
  return f;
}
template <class T>
T factorial(ll n) {
  return permutation<T>(n, n);
}
template <class T>
T binomial(ll n, ll k) {
  return permutation<T>(n, k) /= factorial<T>(k);
}
template <ll Mod>
class modint {
 public:
  ll n = 0;
  modint() {}
  modint(ll n) : n(n) { clamp(); }
  modint& operator=(modint const& a) = default;
  modint& operator=(int a) {
    n = a;
    clamp();
    return *this;
  }
  modint operator-() {
    modint t = *this;
    t.n = -t.n;
    t.clamp();
    return t;
  }
  modint& operator*=(modint const& a) {
    n *= a.n;
    clamp();
    return *this;
  }
  modint& operator*=(ll a) {
    n *= a;
    clamp();
    return *this;
  }
  modint& operator/=(modint const& a) {
    *this *= a.inv();
    return *this;
  }
  modint& operator+=(modint const& a) {
    n += a.n;
    if (n >= Mod) n -= Mod;
    return *this;
  }
  modint& operator-=(modint const& a) {
    n -= a.n;
    if (n < 0) n += Mod;
    return *this;
  }
  modint& operator%=(modint const& a) {
    n %= a.n;
    clamp();
    return *this;
  }
  friend modint operator*(modint a, modint b) {
    modint t(a);
    t.n *= b.n;
    t.clamp();
    return t;
  }
  friend modint operator+(modint a, modint b) {
    modint t(a);
    t.n += b.n;
    t.clamp();
    return t;
  }
  friend modint operator-(modint a, modint b) {
    modint t(a);
    t.n -= b.n;
    t.clamp();
    return t;
  }
  friend ostream& operator<<(ostream& os, modint const& a) {
    os << a.n;
    return os;
  }
  friend bool operator==(modint const& a, int b) { return a.n == b; }
  void clamp() {
    n %= Mod;
    if (n < 0) n += Mod;
  }
  modint inv() const { return this->pow(Mod - 2); }
  ll get() { return n; }
  modint pow(ll p) const {
    ll a = 1, e = n;
    while (p > 0) {
      if (p & 1) {
        a *= e;
        a %= Mod;
      }
      e *= e;
      e %= Mod;
      p >>= 1;
    }
    return modint(a);
  }
};
const ll Mod = 998244353;
using mint = modint<Mod>;
mint dp[100005];
mint sum[100005];
int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ;
  ll ans = 0;
  ll N, K;
  cin >> N >> K;
  vector<pair<int, int>> v;
  for (ll i = 0; i < K; ++i) {
    int l, r;
    cin >> l >> r;
    v.push_back({l, r});
  }
  dp[1] = 1;
  sum[1] = 1;
  for (int i = 2; i <= N; ++i) {
    for (auto p : v) {
      int lpos = max(i - p.second - 1, 0);
      int rpos = max(i - p.first, 0);
      mint s = sum[rpos] - sum[lpos];
      dp[i] += s;
    }
    sum[i] += dp[i] + sum[i - 1];
  }
  cout << dp[N] << '\n';
}
