#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3fffffff;
const long long int INF = 0x1fffffffffffffff;
const double eps = 1e-12;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <unsigned mod = 998244353>
struct mint {
  unsigned val;
  static unsigned get_mod() { return mod; }
  unsigned inv() const {
    int tmp, a = val, b = mod, x = 1, y = 0;
    while (b) tmp = a / b, a -= tmp * b, swap(a, b), x -= tmp * y, swap(x, y);
    if (x < 0) x += mod;
    return x;
  }
  mint() : val(0) {}
  mint(long long int x) : val(x >= 0 ? x % mod : mod + (x % mod)) {}
  mint pow(long long int t) {
    mint res = 1, b = *this;
    while (t) {
      if (t & 1) res *= b;
      b *= b;
      t >>= 1;
    }
    return res;
  }
  mint& operator+=(const mint& x) {
    if ((val += x.val) >= mod) val -= mod;
    return *this;
  }
  mint& operator-=(const mint& x) {
    if ((val += mod - x.val) >= mod) val -= mod;
    return *this;
  }
  mint& operator*=(const mint& x) {
    val = long long int(val) * x.val % mod;
    return *this;
  }
  mint& operator/=(const mint& x) {
    val = long long int(val) * x.inv() % mod;
    return *this;
  }
  mint operator+(const mint& x) const { return mint(*this) += x; }
  mint operator-(const mint& x) const { return mint(*this) -= x; }
  mint operator*(const mint& x) const { return mint(*this) *= x; }
  mint operator/(const mint& x) const { return mint(*this) /= x; }
  bool operator==(const mint& x) const { return val == x.val; }
  bool operator!=(const mint& x) const { return val != x.val; }
};
using Mint = mint<>;
template <typename T>
struct factorial {
  vector<T> Fact, Finv, Inv;
  factorial(int maxx) {
    Fact.resize(maxx);
    Finv.resize(maxx);
    Inv.resize(maxx);
    Fact[0] = Fact[1] = Finv[0] = Finv[1] = Inv[1] = 1;
    unsigned mod = Mint::get_mod();
    for (int i = (2); i < (maxx); i++) {
      Fact[i] = Fact[i - 1] * i;
      Inv[i] = Inv[mod % i] * (mod - mod / i);
      Finv[i] = Finv[i - 1] * Inv[i];
    }
  }
  T fact(int n, bool inv = 0) {
    if (inv)
      return Finv[n];
    else
      return Fact[n];
  }
  T inv(int n) { return Inv[n]; }
  T nPr(int n, int r) {
    if (n < 0 || n < r || r < 0)
      return Mint(0);
    else
      return Fact[n] * Finv[n - r];
  }
  T nCr(int n, int r) {
    if (n < 0 || n < r || r < 0)
      return Mint(0);
    else
      return Fact[n] * Finv[r] * Finv[n - r];
  }
};
template <typename T, unsigned p>
struct NTT {
  vector<T> rt, irt;
  NTT(int lg = 21) {
    unsigned mod = T::get_mod();
    T prt = p;
    rt.resize(1 << lg, 1);
    irt.resize(1 << lg, 1);
    for (int w = (0); w < (lg); w++) {
      int mask = (1 << w) - 1, t = (mod - 1) >> w;
      T g = prt.pow(t), ig = prt.pow(mod - 1 - t);
      for (int i = (0); i < (mask); i++) {
        rt[mask + i + 1] = g * rt[mask + i];
        irt[mask + i + 1] = ig * irt[mask + i];
      }
    }
  }
  void ntt(vector<T>& f, bool inv = 0) {
    int n = f.size();
    if (inv) {
      for (int i = 1; i < n; i <<= 1)
        for (int j = 0; j < n; j += i * 2)
          for (int k = (0); k < (i); k++) {
            f[i + j + k] *= irt[i * 2 - 1 + k];
            const T tmp = f[j + k] - f[i + j + k];
            f[j + k] += f[i + j + k];
            f[i + j + k] = tmp;
          }
      T mul = T(n).inv();
      for (int i = (0); i < (n); i++) f[i] *= mul;
    } else {
      for (int i = n >> 1; i; i >>= 1)
        for (int j = 0; j < n; j += i * 2)
          for (int k = (0); k < (i); k++) {
            const T tmp = f[j + k] - f[i + j + k];
            f[j + k] += f[i + j + k];
            f[i + j + k] = tmp * rt[i * 2 - 1 + k];
          }
    }
  }
  vector<T> conv(vector<T> a, vector<T> b) {
    int n = a.size() + b.size() - 1,
        m = (n & (n - 1) ? 1 << (32 - __builtin_clz(n)) : n);
    a.resize(m);
    b.resize(m);
    ntt(a);
    ntt(b);
    for (int i = (0); i < (m); i++) a[i] *= b[i];
    ntt(a, 1);
    a.resize(n);
    return a;
  }
};
NTT<Mint, 3> ntt;
vector<Mint> multiply(vector<Mint> a, vector<Mint> b) {
  return ntt.conv(a, b);
};
template <typename T>
struct FPS {
  using V = vector<T>;
  V f;
  FPS() {}
  FPS(int _n) : f(_n) {}
  FPS(V _f) { f = _f; }
  T& operator[](const int i) { return f[i]; }
  T eval(Mint x) {
    T res, w = 1;
    for (T v : f) res += w * v, w *= x;
    return res;
  }
  int size() const { return f.size(); }
  FPS resize(int n) {
    f.resize(n);
    return *this;
  }
  void shrink() {
    while (!f.empty() and f.back() == 0) f.pop_back();
  }
  FPS inv() const {
    assert(f[0] != 0);
    int n = f.size();
    FPS res(n);
    res[0] = f[0].inv();
    for (int k = 1; k < n; k <<= 1) {
      FPS g(k), h(k * 2);
      for (int i = (0); i < (min(k, n)); i++) g[i] = res[i];
      for (int i = (0); i < (min(k * 2, n)); i++) h[i] = f[i];
      g *= g;
      g *= h;
      g.resize(k * 2);
      for (int i = (0); i < (min(k * 2, n)); i++) res[i] = res[i] * 2 - g[i];
    }
    return res;
  }
  FPS operator+(const FPS& g) const { return FPS(*this) += g; }
  FPS operator-(const FPS& g) const { return FPS(*this) -= g; }
  FPS operator*(const FPS& g) const { return FPS(*this) *= g; }
  FPS operator/(const FPS& g) const { return FPS(*this) /= g; }
  FPS operator%(const FPS& g) const { return FPS(*this) %= g; }
  FPS& operator+=(FPS g) {
    if (g.size() > f.size()) f.resize(g.size());
    for (int i = (0); i < (g.size()); i++) f[i] += g[i];
    shrink();
    return *this;
  }
  FPS& operator-=(FPS g) {
    if (g.size() > f.size()) f.resize(g.size());
    for (int i = (0); i < (g.size()); i++) f[i] -= g[i];
    shrink();
    return *this;
  }
  FPS& operator*=(FPS g) {
    f = multiply(f, g.f);
    shrink();
    return *this;
  }
  FPS& operator/=(FPS g) {
    if (g.size() > f.size()) return *this = FPS();
    reverse((f).begin(), (f).end());
    reverse((g.f).begin(), (g.f).end());
    int n = f.size() - g.size() + 1;
    f.resize(n);
    g.resize(n);
    *this *= g.inv();
    f.resize(n);
    reverse((f).begin(), (f).end());
    shrink();
    return *this;
  }
  FPS& operator%=(FPS g) {
    *this -= *this / g * g;
    shrink();
    return *this;
  }
  FPS diff() {
    FPS res(f.size() - 1);
    for (int i = (0); i < (res.size()); i++) res[i] = f[i + 1] * (i + 1);
    return res;
  }
  FPS inte() {
    FPS res(f.size() + 1);
    for (int i = res.size() - 1; i; i--) res[i] = f[i - 1] / i;
    return res;
  }
  FPS log() {
    assert(f[0] == 1);
    int n = f.size();
    FPS res = diff() * inv();
    res = res.inte();
    return res.resize(n);
  }
  FPS exp() {
    assert(f[0] == 0);
    int n = f.size();
    FPS f(1), g(1);
    f[0] = g[0] = 1;
    for (int k = 1; k < n; k <<= 1) {
      g = (g + g - f * g * g).resize(k);
      FPS q = diff().resize(k - 1);
      FPS w = (q + g * (f.diff() - f * q)).resize(2 * k - 1);
      f = (f + f * (*this - w.inte()).resize(2 * k)).resize(2 * k);
    }
    return f.resize(n);
  }
  FPS shift(int c) {
    int n = f.size();
    FPS res = *this, mul(n);
    factorial<T> fact(n + 1);
    mul[1] = c;
    mul = mul.exp();
    for (int i = (0); i < (n); i++) res[i] *= fact.fact(i);
    reverse((res.f).begin(), (res.f).end());
    res *= mul;
    res.resize(n);
    reverse((res.f).begin(), (res.f).end());
    for (int i = (0); i < (n); i++) res[i] *= fact.fact(i, 1);
    return res;
  }
  FPS pow(long long int t) {
    int n = f.size(), k = 0;
    while (k < n and f[k] == 0) k++;
    FPS res(n);
    if (t * k >= n) return res;
    n -= t * k;
    FPS tmp(n);
    Mint c = f[k], ic = c.inv();
    for (int i = (0); i < (n); i++) tmp[i] = f[i + k] * ic;
    tmp = tmp.log();
    for (auto& x : tmp.f) x *= t;
    tmp = tmp.exp();
    c = c.pow(t);
    for (int i = (0); i < (n); i++) res[i + t * k] = tmp[i] * c;
    return res;
  }
};
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  FPS<Mint> f(n + 1);
  for (int i = 0; i < n; ++i) f[i].val = 0;
  for (int i = 0; i < m; ++i) {
    int L, R;
    cin >> L >> R;
    for (int j = L; j <= R; ++j) {
      f[j].val = 1;
    }
  }
  auto g = f.pow(n);
  f[0].val = 998244353 - 1;
  g[0].val = 998244353 - 1;
  f = f.inv();
  g = g * f;
  cout << g[n - 1].val << endl;
  return 0;
}
