#include <bits/stdc++.h>
using ll = int64_t;
using namespace std;
template <int mod>
struct modint {
  ll x;
  modint(ll x = 0) : x((x % mod + mod) % mod) {}
  modint operator-() const { return modint(mod - x); }
  modint inv() const { return this->pow(mod - 2); }
  modint& operator+=(const modint& a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  modint& operator-=(const modint& a) {
    if ((x -= a.x) < 0) x += mod;
    return *this;
  }
  modint& operator*=(const modint& a) {
    (x *= a.x) %= mod;
    return *this;
  }
  modint& operator/=(const modint& a) { return *this *= a.inv(); }
  modint operator-(const modint& a) const { return modint(*this) -= a; }
  modint operator+(const modint& a) const { return modint(*this) += a; }
  modint operator*(const modint& a) const { return modint(*this) *= a; }
  modint operator/(const modint& a) const { return modint(*this) /= a; }
  modint pow(ll n) const {
    auto x = modint(1);
    auto m = *this;
    while (n > 0) {
      if (n & 1) x *= m;
      n >>= 1;
      m *= m;
    }
    return x;
  }
  bool operator==(const modint& a) const { return x == a.x; }
  bool operator!=(const modint& a) const { return x != a.x; }
  friend istream& operator>>(istream& is, modint& a) noexcept {
    return is >> a.x;
  }
  friend ostream& operator<<(ostream& os, const modint& a) noexcept {
    return os << a.x;
  }
};
constexpr int mod = 998244353;
using mint = modint<mod>;
mint mpow(mint a, mint b) {
  auto x = mint(1), m = a;
  auto n = b.x;
  while (n > 0) {
    if (n & 1) x *= m;
    n >>= 1;
    m *= m;
  }
  return x;
}
vector<mint> mintcombvector;
int startmintcomb(int n) {
  mintcombvector.push_back(0);
  mintcombvector.push_back(1);
  for (int i = 0; i < (n); ++i)
    mintcombvector.push_back(mintcombvector[i + 1] * (i + 2));
  return 0;
}
mint comb(mint a, mint b) {
  if (a.x < b.x || a.x <= 0 || b.x < 0) return mint(0);
  if (b.x == 0) return mint(1);
  if (a == b) return mint(1);
  return mintcombvector[a.x] * (mintcombvector[b.x].inv()) *
         (mintcombvector[a.x - b.x].inv());
}
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> p(k), m(k);
  for (int i = 0; i < (k); ++i) {
    cin >> p[i] >> m[i];
    m[i]++;
  }
  vector<mint> ans(n + 1, 0);
  mint now = 0;
  for (int i = 0; i < (k); ++i) {
    ans[p[i]] += 1;
    if (m[i] <= n) {
      ans[m[i]] -= 1;
    }
  }
  now = ans[1];
  for (int i = 1; i < n; ++i) {
    now += ans[i];
    if (now.x > 0) {
      for (int j = 0; j < (k); ++j) {
        if (p[j] + i <= n) {
          ans[p[j] + i] += now;
        }
        if (m[j] + i <= n) {
          ans[m[j] + i] -= now;
        }
      }
    }
  }
  if (ans[n - 1] == -1) {
    cout << 0 << endl;
    return 0;
  }
  cout << ans[n - 1] << endl;
  return 0;
}
