#include <bits/stdc++.h>
using namespace std;

template<typename T, typename U> void cmax(T &a, U b) { if (a < b) a = b; }
template<typename T, typename U> void cmin(T &a, U b) { if (a > b) a = b; }

template <unsigned int mod> class modint {
private:
  unsigned int v;
  static unsigned int norm(const unsigned int& x) { return x < mod ? x : x - mod; }
  static modint make(const unsigned int& x) { modint m; return m.v = x, m; }
  static modint inv(const modint& x) { return make(inverse(x.v, mod)); }
  static unsigned int inverse(int a, int m) {
    int u[] = {a, 1, 0}, v[] = {m, 0, 1}, t;
    while (*v) {
      t = *u / *v;
      swap(u[0] -= t * v[0], v[0]), swap(u[1] -= t * v[1], v[1]), swap(u[2] -= t * v[2], v[2]);
    }
    return (u[1] % m + m) % m;
  }

public:
  modint() : v{0} {}
  modint(const long val) : v{norm(val % mod + mod)} {}
  modint(const modint<mod>& n) : v{n()} {}
  explicit operator bool() const noexcept { return v != 0; }
  bool operator!() const noexcept { return !static_cast<bool>(*this); }
  modint& operator=(const modint& n) { return v = n(), (*this); }
  modint& operator=(const long val) { return v = norm(val % mod + mod), (*this); }
  modint operator+() const { return *this; }
  modint operator-() const { return v == 0 ? make(0) : make(mod - v); }
  modint operator+(const modint& val) const { return make(norm(v + val())); }
  modint operator-(const modint& val) const { return make(norm(v + mod - val())); }
  modint operator*(const modint& val) const { return make((long)v * val() % mod); }
  modint operator/(const modint& val) const { return *this * inv(val); }
  modint& operator+=(const modint& val) { return *this = *this + val; }
  modint& operator-=(const modint& val) { return *this = *this - val; }
  modint& operator*=(const modint& val) { return *this = *this * val; }
  modint& operator/=(const modint& val) { return *this = *this / val; }
  modint operator+(const long val) const { return modint{v + val}; }
  modint operator-(const long val) const { return modint{v - val}; }
  modint operator*(const long val) const { return modint{(long)(v * (val % mod))}; }
  modint operator/(const long val) const { return modint{(long)v * inv(val)}; }
  modint& operator+=(const long val) { return *this = *this + val; }
  modint& operator-=(const long val) { return *this = *this - val; }
  modint& operator*=(const long val) { return *this = *this * val; }
  modint& operator/=(const long val) { return *this = *this / val; }
  bool operator==(const modint& val) const { return v == val.v; }
  bool operator!=(const modint& val) const { return !(*this == val); }
  bool operator==(const long val) const { return v == norm(val % mod + mod); }
  bool operator!=(const long val) const { return !(*this == val); }
  unsigned int operator()() const { return v; }
  friend modint operator+(const long val, const modint& n) { return n + val; }
  friend modint operator-(const long val, const modint& n) { return modint{val - n()}; }
  friend modint operator*(const long val, const modint& n) { return n * val; }
  friend modint operator/(const long val, const modint& n) { return modint{val} / n; }
  friend bool operator==(const long val, const modint& n) { return n == val; }
  friend bool operator!=(const long val, const modint& n) { return !(val == n); }
  friend istream& operator>>(istream& is, modint& n) {
    unsigned int v;
    return is >> v, n = v, is;
  }
  friend ostream& operator<<(ostream& os, const modint& n) { return (os << n()); }
};

// constexpr int MOD = 1000000007;
constexpr int MOD = 998244353;
using mint = modint<MOD>;

constexpr int MAX = 5000000;
vector<long> fact(MAX), finv(MAX), inve(MAX);

void init() {
  fact.at(0) = fact.at(1) = 1;
  finv.at(0) = finv.at(1) = 1;
  inve.at(1) = 1;
  for (int i = 2; i < MAX; i++) {
    fact.at(i) = fact.at(i - 1) * i % MOD;
    inve.at(i) = MOD - inve.at(MOD % i) * (MOD / i) % MOD;
    finv.at(i) = finv.at(i - 1) * inve.at(i) % MOD;
  }
}

long com(long n, long r) {
  if (n < r || n < 0 || r < 0) return 0;
  return fact.at(n) * (finv.at(r) * finv.at(n - r) % MOD) % MOD;
}

long mpow(long a, long b) {
  long res = 1;
  while (b > 0) {
    if (b & 1) res = res * a % MOD;
    a = a * a % MOD;
    b >>= 1;
  }
  return res;
}

long com2(long n, long r) {
  if (n < r || n < 0 || r < 0) return 0;
  long x = 1, y = 1;
  for (int i = 1; i <= r; i++) {
    x = x * (n - i + 1) % MOD;
    y = y * i % MOD;
  }
  return x * mpow(y, MOD - 2) % MOD;
}

long inv(long a) {
  long b = MOD, u = 1, v = 0;
  while (b) {
    long t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= MOD;
  if (u < 0) u += MOD;
  return u;
}

template<typename T> class SegmentTree {
private:
  int n, sz, h;
  vector<T> node, lazy;
  void eval(int k) {
    if (lazy.at(k)) {
      node.at(k) += lazy.at(k);
      if (k < n) lazy.at(k * 2) += lazy.at(k) / 2, lazy.at(k * 2 + 1) += lazy.at(k) / 2;
      lazy.at(k) = 0;
    }
  }
public:
  SegmentTree(const vector<T> &v) : sz((int) v.size()), h(0) {
    n = 1;
    while (n < sz) n *= 2, h++;
    node.resize(2 * n, 0), lazy.resize(2 * n, 0);
    for (int i = 0; i < sz; i++) node.at(i + n) = v.at(i);
    for (int i = n - 1; i >= 1; i--) node.at(i) = node.at(2 * i) + node.at(2 * i + 1);
  }
  void add(int a, int b, T x) {
    a += n, b += n - 1;
    for (int i = h; i > 0; i--) eval(a >> i), eval(b >> i);
    int ta = a, tb = b++, length = 1;
    while (a < b) {
      if (a & 1) lazy.at(a++) += length * x;
      if (b & 1) lazy.at(--b) += length * x;
      a >>= 1, b >>= 1, length <<= 1;
    }
    while (ta >>= 1, tb >>= 1, ta) {
      if (!lazy.at(ta)) {
        eval(2 * ta), eval(2 * ta + 1), node.at(ta) = node.at(2 * ta) + node.at(2 * ta + 1);
      }
      if (!lazy.at(tb)) {
        eval(2 * tb), eval(2 * tb + 1), node.at(tb) = node.at(2 * tb) + node.at(2 * tb + 1);
      }
    }
  }
  T sum(int a, int b) {
    a += n, b += n - 1;
    for (int i = h; i > 0; i--) eval(a >> i), eval(b >> i);
    b++;
    T res1 = 0, res2 = 0;
    while (a < b) {
      if (a & 1) eval(a), res1 += node.at(a++);
      if (b & 1) eval(--b), res2 += node.at(b);
      a >>= 1, b >>= 1;
    }
    return res1 + res2;
  }
};

signed main() {
  int N, K;
  cin >> N >> K;
  vector<pair<int, int>> V(K);
  for (int i = 0; i < K; i++) {
    int l, r;
    cin >> l >> r;
    V.at(i) = {l, r};
  }

  vector<mint> X(N * 3);
  SegmentTree<mint> ST(X);
  ST.add(1, 2, 1);
  for (int i = 1; i < N; i++) {
    mint now = ST.sum(i, i + 1);
    if (now != 0) {
      for (auto [l, r] : V) {
        ST.add(i + l, i + r + 1, now);
      }
    }
  }
  cout << ST.sum(N, N + 1) << "\n";
}

Measured memory_bytes: 139232