#include <bits/stdc++.h>
using namespace std;
static const double EPS = 1e-12;
static const double PI = acos(-1.0);
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;
const int mod = 998244353;
struct mint {
  long long x;
  mint(long long 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 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 { return mint(*this) /= a; }
};
istream &operator>>(istream &is, const mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }
mint dp[200005];
void solve(long long N, long long K, std::vector<long long> L,
           std::vector<long long> R) {
  for (int i = 0; i < (int)(K); i++) {
    dp[L[i]] += 1;
    dp[R[i] + 1] -= 1;
  }
  mint cur = 0;
  for (int j = (int)(1); j < (int)(N); j++) {
    cur += dp[j];
    for (int i = 0; i < (int)(K); i++) {
      dp[L[i] + j] += cur;
      dp[R[i] + 1 + j] -= cur;
    }
  }
  cout << cur << endl;
}
int main() {
  long long N;
  scanf("%lld", &N);
  long long K;
  scanf("%lld", &K);
  std::vector<long long> L(K);
  std::vector<long long> R(K);
  for (int i = 0; i < K; i++) {
    scanf("%lld", &L[i]);
    scanf("%lld", &R[i]);
  }
  solve(N, K, std::move(L), std::move(R));
  return 0;
}
