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

// template
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
typedef long long int ll;
const int inf = 0x3fffffff;
const ll 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;
}
// end

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(ll x) : val(x >= 0 ? x % mod : mod + (x % mod)) {}
  mint pow(ll 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 = ll(val) * x.val % mod;
    return *this;
  }
  mint &operator/=(const mint &x) {
    val = ll(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();
    rep(i, 2, maxx) {
      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);
    rep(w, 0, lg) {
      int mask = (1 << w) - 1, t = (mod - 1) >> w;
      T g = prt.pow(t), ig = prt.pow(mod - 1 - t);
      rep(i, 0, mask) {
        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)
          rep(k, 0, i) {
            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();
      rep(i, 0, n) f[i] *= mul;
    } else {
      for (int i = n >> 1; i; i >>= 1)
        for (int j = 0; j < n; j += i * 2)
          rep(k, 0, i) {
            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);
    rep(i, 0, m) 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);
      rep(i, 0, min(k, n)) g[i] = res[i];
      rep(i, 0, min(k * 2, n)) h[i] = f[i];
      g *= g;
      g *= h;
      g.resize(k * 2);
      rep(i, 0, min(k * 2, n)) 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());
    rep(i, 0, g.size()) f[i] += g[i];
    shrink();
    return *this;
  }
  FPS &operator-=(FPS g) {
    if (g.size() > f.size())
      f.resize(g.size());
    rep(i, 0, g.size()) 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(ALL(f));
    reverse(ALL(g.f));
    int n = f.size() - g.size() + 1;
    f.resize(n);
    g.resize(n);
    *this *= g.inv();
    f.resize(n);
    reverse(ALL(f));
    shrink();
    return *this;
  }
  FPS &operator%=(FPS g) {
    *this -= *this / g * g;
    shrink();
    return *this;
  }
  FPS diff() {
    FPS res(f.size() - 1);
    rep(i, 0, res.size()) 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();
    rep(i, 0, n) res[i] *= fact.fact(i);
    reverse(ALL(res.f));
    res *= mul;
    res.resize(n);
    reverse(ALL(res.f));
    rep(i, 0, n) res[i] *= fact.fact(i, 1);
    return res;
  }
  FPS pow(ll 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();
    rep(i, 0, n) tmp[i] = f[i + k] * ic;
    tmp = tmp.log();
    for (auto &x : tmp.f)
      x *= t;
    tmp = tmp.exp();
    c = c.pow(t);
    rep(i, 0, n) 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;
}

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

// template
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
typedef long long int ll;
const int inf = 0x3fffffff;
const ll 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;
}
// end

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(ll x) : val(x >= 0 ? x % mod : mod + (x % mod)) {}
  mint pow(ll 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 = ll(val) * x.val % mod;
    return *this;
  }
  mint &operator/=(const mint &x) {
    val = ll(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();
    rep(i, 2, maxx) {
      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);
    rep(w, 0, lg) {
      int mask = (1 << w) - 1, t = (mod - 1) >> w;
      T g = prt.pow(t), ig = prt.pow(mod - 1 - t);
      rep(i, 0, mask) {
        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)
          rep(k, 0, i) {
            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();
      rep(i, 0, n) f[i] *= mul;
    } else {
      for (int i = n >> 1; i; i >>= 1)
        for (int j = 0; j < n; j += i * 2)
          rep(k, 0, i) {
            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);
    rep(i, 0, m) 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);
      rep(i, 0, min(k, n)) g[i] = res[i];
      rep(i, 0, min(k * 2, n)) h[i] = f[i];
      g *= g;
      g *= h;
      g.resize(k * 2);
      rep(i, 0, min(k * 2, n)) 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());
    rep(i, 0, g.size()) f[i] += g[i];
    shrink();
    return *this;
  }
  FPS &operator-=(FPS g) {
    if (g.size() > f.size())
      f.resize(g.size());
    rep(i, 0, g.size()) 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(ALL(f));
    reverse(ALL(g.f));
    int n = f.size() - g.size() + 1;
    f.resize(n);
    g.resize(n);
    *this *= g.inv();
    f.resize(n);
    reverse(ALL(f));
    shrink();
    return *this;
  }
  FPS &operator%=(FPS g) {
    *this -= *this / g * g;
    shrink();
    return *this;
  }
  FPS diff() {
    FPS res(f.size() - 1);
    rep(i, 0, res.size()) 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();
    rep(i, 0, n) res[i] *= fact.fact(i);
    reverse(ALL(res.f));
    res *= mul;
    res.resize(n);
    reverse(ALL(res.f));
    rep(i, 0, n) res[i] *= fact.fact(i, 1);
    return res;
  }
  FPS pow(ll 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();
    rep(i, 0, n) tmp[i] = f[i + k] * ic;
    tmp = tmp.log();
    for (auto &x : tmp.f)
      x *= t;
    tmp = tmp.exp();
    c = c.pow(t);
    rep(i, 0, n) res[i + t * k] = tmp[i] * c;
    return res;
  }
};

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  FPS<Mint> f(n + 10);
  for (int i = 0; i < n + 10; ++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;
  if (g.size() >= n) {
    cout << g[n - 1].val << endl;
  } else {
    cout << 0 << endl;
  }

  return 0;
}


#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
// #define int long long
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep1(i, n) for (int i = 1; i <= n; ++i)
#define ALL(x) x.begin(), x.end()
#define debug(output) cout << #output << "= " << output << endl

using P = pair<int, int>;
using lint = long long;
using ll = long long;
const lint inf = 1e18 + 7;
const int MOD = 998244353;
signed main() {
  int n, k;
  cin >> n >> k;
  vector<int> a;
  rep(i, k) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; ++j)
      a.push_back(j);
  }
  vector<int> dp(n + 1, 0);
  dp[1] = 1;
  int num = a.size();
  sort(a.begin(), a.end());
  for (int j = 1; j < n; ++j) {
    rep(i, num) {
      if (a[i] + j > n)
        break;
      dp[a[i] + j] += dp[j];
      dp[a[i] + j] %= MOD;
    }
  }
  cout << dp[n] << "\\n";
  return 0;
}

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep1(i, n) for (int i = 1; i <= n; ++i)
#define ALL(x) x.begin(), x.end()
#define debug(output) cout << #output << "= " << output << endl

using P = pair<int, int>;
using lint = long long;
using ll = long long;
const lint inf = 1e18 + 7;
const int MOD = 998244353;
// 区間加算を行うセグ木
// indexは0~n-1まで
class Seg_Tree {
private:
  int n;
  vector<int> node;

public:
  int process(int left, int right) {
    if (left == inf)
      return right;
    if (right == inf)
      return left;
    int ans = left;
    if (left > right)
      ans = right;
    return ans;
  }
  Seg_Tree(vector<int> v) {
    int num = 1;
    int size = v.size();
    while (num < size) {
      num *= 2;
    }
    n = num;
    node.resize(2 * num - 1, 0);
    for (int i = 0; i < size; i++)
      node[i + num - 1] = v[i];
    for (int i = n - 2; i >= 0; i--)
      node[i] = process(node[i * 2 + 1], node[i * 2 + 2]);
  }
  int get(int x) {
    x += (n - 1);
    int res = node[x];
    while (x > 0) {
      x = (x - 1) / 2;
      res += node[x];
      res %= MOD;
    }
    res += node[0];
    res %= MOD;
    return res;
  }
  void add(int a, int b, int value, int k = 0, int l = 0, int r = -1) {
    if (r < 0)
      r = n;
    if (a >= r || b <= l)
      goto FINE;
    if (a <= l && b >= r) {
      node[k] += value;
      node[k] %= MOD;
      goto FINE;
    }
    add(a, b, value, k * 2 + 1, l, (l + r) / 2);
    add(a, b, value, k * 2 + 2, (l + r) / 2, r);
  // return process(vl,vr);
  FINE:;
  }
};
signed main() {
  int n, k;
  cin >> n >> k;
  vector<int> l(k), r(k);
  rep(i, k) cin >> l[i] >> r[i];
  Seg_Tree dp(vector<int>(n * 2 + 10, 0));
  dp.add(1, 2, 1);
  for (int j = 1; j <= n; ++j) {
    rep(i, k) { dp.add(j + l[i], j + r[i] + 1, dp.get(j)); }
  }
  cout << dp.get(n) << "\\n";
  rep1(i, n) {
    lint hoge = dp.get(i);
    // debug(hoge);
  }
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define endl '\\n'
#define deb(x) cout << #x << " = " << x << endl;
typedef long long ll;
typedef double dd;
const int MOD = 998244353;

vector<int> dp, v;
int n;

int recc(int i) {
  if (i > n)
    return 0;
  if (i == n)
    return 1;
  if (dp[i - 1] != -1)
    return dp[i - 1];
  int ans = 0;
  for (int j = 0; j < (int)v.size(); j++) {
    if (i + v[j] > n)
      break;
    int temp = recc(i + v[j]) % MOD;
    ans = (ans % MOD + temp) % MOD;
  }
  return dp[i - 1] = ans;
}

void solve() {
  int k;
  cin >> n >> k;
  while (k--) {
    int l, r;
    cin >> l >> r;
    for (int i = l; i <= r; i++)
      v.push_back(i);
  }
  sort(v.begin(), v.end());
  dp.resize(n, -1);
  int ans = recc(1) % MOD;
  cout << ans << endl;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int t = 1, tt = 0;
  // cin >> t;
  while (t--) {
    // tt++;
    // cout << "Case #" << t << ": ";
    solve();
  }
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define endl '\\n'
#define deb(x) cout << #x << " = " << x << endl;
typedef long long ll;
typedef double dd;
const int MOD = 998244353;
#define ff first
#define ss second

template <typename T> string to_string(vector<T> v) {
  string res;
  for (auto &i : v)
    res += char('0' + i), res += ' ';
  return res;
}

template <class A> void vbug(A x) { cout << to_string(x) << endl; }

void solve() {
  int n, k;
  cin >> n >> k;
  vector<pair<int, int>> v(k);
  for (int i = 0; i < k; i++) {
    cin >> v[i].ff >> v[i].ss;
  }
  vector<int> dp(n + 1, 0), pre(n + 1, 0);
  dp[0] = 0;
  dp[1] = pre[1] = 1;
  for (int i = 2; i <= n; i++) {
    int tmp = 0;
    for (auto j : v) {
      int l = i - j.ff;
      int r = i - j.ss - 1;
      l = max(0, l);
      r = max(0, r);
      tmp = ((tmp + pre[l]) % MOD - pre[r]) % MOD;
    }
    tmp = (tmp + MOD) % MOD;
    dp[i] = tmp;
    pre[i] = (pre[i - 1] + dp[i]) % MOD;
  }
  // vbug(dp);
  cout << dp[n] << endl;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int t = 1, tt = 0;
  // cin >> t;
  while (t--) {
    // tt++;
    // cout << "Case #" << t << ": ";
    solve();
  }
  return 0;
}


#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 25;
const int MOD = 998244353;
const int N = 2 * 1e5 + 100;
int l, r;
vector<int> s;
int dp[N];
int main() {
  int n, k;
  cin >> n >> k;
  rep(i, k) {
    cin >> l >> r;
    for (int i = l; i <= r; i++)
      s.push_back(i);
  }
  int m = s.size();

  dp[0] = 1;
  rep(i, n) {
    rep(j, m) {
      if (i + s[j] >= n)
        continue;
      dp[i + s[j]] += dp[i];
      dp[i + s[j]] %= MOD;
    }
  }
  cout << dp[n - 1] << endl;
  return 0;
}

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 25;
const int MOD = 998244353;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> l(k), r(k);
  rep(j, k) cin >> l[j] >> r[j];

  vector<ll> dp(n + 1, 0);
  vector<ll> dpsum(n + 1, 0);
  dp[1] = 1;
  dpsum[1] = 1;
  for (int i = 2; i <= n; i++) {
    rep(j, k) {
      int li = i - r[j];
      int ri = i - l[j];
      if (ri < 0)
        continue;
      li = max(1, li);
      dp[i] += dpsum[ri] - dpsum[li - 1];
      // dp[i] = (dp[i]+MOD) % MOD;
      dp[i] %= MOD;
    }
    dpsum[i] = dpsum[i - 1] + dp[i];
    dpsum[i] %= MOD;
    // dpsum[i] = (dpsum[i]+MOD) % MOD;
  }
  cout << (dp[n] + MOD) % MOD << endl;
  return 0;
}


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

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using P = pair<ll, ll>;
string char_to_string(char val) { return string(1, val); }
int char_to_int(char val) { return val - '0'; }
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
struct edge {
  ll to, cost;
};

// modint: mod 計算を int を扱うように扱える構造体
template <int MOD> struct Fp {
  long long val;
  constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
    if (val < 0)
      val += MOD;
  }
  constexpr int getmod() { return MOD; }
  constexpr Fp operator-() const noexcept { return val ? MOD - val : 0; }
  constexpr Fp operator+(const Fp &r) const noexcept { return Fp(*this) += r; }
  constexpr Fp operator-(const Fp &r) const noexcept { return Fp(*this) -= r; }
  constexpr Fp operator*(const Fp &r) const noexcept { return Fp(*this) *= r; }
  constexpr Fp operator/(const Fp &r) const noexcept { return Fp(*this) /= r; }
  constexpr Fp &operator+=(const Fp &r) noexcept {
    val += r.val;
    if (val >= MOD)
      val -= MOD;
    return *this;
  }
  constexpr Fp &operator-=(const Fp &r) noexcept {
    val -= r.val;
    if (val < 0)
      val += MOD;
    return *this;
  }
  constexpr Fp &operator*=(const Fp &r) noexcept {
    val = val * r.val % MOD;
    return *this;
  }
  constexpr Fp &operator/=(const Fp &r) noexcept {
    long long a = r.val, b = MOD, u = 1, v = 0;
    while (b) {
      long long t = a / b;
      a -= t * b;
      swap(a, b);
      u -= t * v;
      swap(u, v);
    }
    val = val * u % MOD;
    if (val < 0)
      val += MOD;
    return *this;
  }
  constexpr bool operator==(const Fp &r) const noexcept {
    return this->val == r.val;
  }
  constexpr bool operator!=(const Fp &r) const noexcept {
    return this->val != r.val;
  }
  friend constexpr ostream &operator<<(ostream &os, const Fp<MOD> &x) noexcept {
    return os << x.val;
  }
  friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
    if (n == 0)
      return 1;
    auto t = modpow(a, n / 2);
    t = t * t;
    if (n & 1)
      t = t * a;
    return t;
  }
};

const int MOD = 998244353;
using mint = Fp<MOD>;

int main() {
  ll N, K;
  cin >> N >> K;
  vector<ll> L(K), R(K);
  REP(i, K) cin >> L[i] >> R[i];
  map<ll, ll> m;
  REP(i, K) {
    for (int k = L[i]; k <= R[i]; ++k) {
      m[k]++;
    }
  }
  vector<mint> dp(N, 0);
  dp[0] = 1;
  REP(i, N) {
    for (auto x : m) {
      if (i + x.first >= N)
        continue;
      dp[i + x.first] += dp[i];
    }
  }
  cout << dp[N - 1] << endl;
}

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

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using P = pair<ll, ll>;
string char_to_string(char val) { return string(1, val); }
int char_to_int(char val) { return val - '0'; }
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
struct edge {
  ll to, cost;
};

// modint: mod 計算を int を扱うように扱える構造体
template <int MOD> struct Fp {
  long long val;
  constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
    if (val < 0)
      val += MOD;
  }
  constexpr int getmod() { return MOD; }
  constexpr Fp operator-() const noexcept { return val ? MOD - val : 0; }
  constexpr Fp operator+(const Fp &r) const noexcept { return Fp(*this) += r; }
  constexpr Fp operator-(const Fp &r) const noexcept { return Fp(*this) -= r; }
  constexpr Fp operator*(const Fp &r) const noexcept { return Fp(*this) *= r; }
  constexpr Fp operator/(const Fp &r) const noexcept { return Fp(*this) /= r; }
  constexpr Fp &operator+=(const Fp &r) noexcept {
    val += r.val;
    if (val >= MOD)
      val -= MOD;
    return *this;
  }
  constexpr Fp &operator-=(const Fp &r) noexcept {
    val -= r.val;
    if (val < 0)
      val += MOD;
    return *this;
  }
  constexpr Fp &operator*=(const Fp &r) noexcept {
    val = val * r.val % MOD;
    return *this;
  }
  constexpr Fp &operator/=(const Fp &r) noexcept {
    long long a = r.val, b = MOD, u = 1, v = 0;
    while (b) {
      long long t = a / b;
      a -= t * b;
      swap(a, b);
      u -= t * v;
      swap(u, v);
    }
    val = val * u % MOD;
    if (val < 0)
      val += MOD;
    return *this;
  }
  constexpr bool operator==(const Fp &r) const noexcept {
    return this->val == r.val;
  }
  constexpr bool operator!=(const Fp &r) const noexcept {
    return this->val != r.val;
  }
  friend constexpr ostream &operator<<(ostream &os, const Fp<MOD> &x) noexcept {
    return os << x.val;
  }
  friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
    if (n == 0)
      return 1;
    auto t = modpow(a, n / 2);
    t = t * t;
    if (n & 1)
      t = t * a;
    return t;
  }
};

const int MOD = 998244353;
using mint = Fp<MOD>;

int main() {
  ll N, K;
  cin >> N >> K;
  vector<ll> L(K), R(K);
  REP(i, K) cin >> L[i] >> R[i];
  vector<mint> dp(N + 1, 0);
  dp[1] = 1;
  vector<mint> sum(N + 1, 0);
  sum[1] = 1;
  for (int i = 2; i <= N; ++i) {
    REP(k, K) {
      // L[i]〜R[i]
      int li = i - R[k];
      int ri = i - L[k];
      li = max(li, 1);
      if (ri < 0)
        continue;
      dp[i] += sum[ri] - sum[li - 1];
    }
    sum[i] += sum[i - 1] + dp[i];
  }
  cout << dp[N] << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
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;
}
typedef int64_t lint;
const int mod = 998244353;
struct mint {
  lint x;
  mint(lint 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(lint t) const {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  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, mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> v;
  int a = 0, b = 0, c = 0, x, y, z;
  rep(i, K) {
    cin >> x >> y;
    for (int i = x; i <= y; i++)
      v.push_back(i);
  }
  sort(all(v));
  vector<mint> dp(N);
  dp[0] = 1;
  rep(i, N) {
    rep(j, v.size()) {
      x = v.at(j);
      if (i + x >= N)
        break;
      dp[i + x] += dp[i];
    }
  }
  std::cout << dp[N - 1] << '\\n';
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
using pint = pair<int, int>;
typedef int64_t lint;
const int mod = 998244353;
struct mint {
  lint x;
  mint(lint 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(lint t) const {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  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, mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }

int main() {
  int N, K;
  cin >> N >> K;
  vector<pint> v(K);
  int a = 0, b = 0, c = 0, x, y, z;
  rep(i, K) {
    cin >> x >> y;
    v.at(i) = make_pair(x, y);
  }
  sort(all(v));
  vector<mint> dp(N);
  dp[0] = 1;
  dp[1] = -1;
  rep(i, N) {
    if (i > 0)
      dp[i] += dp[i - 1];
    rep(j, v.size()) {
      tie(x, y) = v.at(j);
      if (i + x < N) {
        dp[i + x] += dp[i];
        if (i + y + 1 < N)
          dp[i + y + 1] -= dp[i];
      }
    }
  }
  std::cout << dp[N - 1] << '\\n';
}


#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>

using namespace std;
typedef long long ll;
const ll M = 998244353;

int main() {
  ll N, K;
  cin >> N >> K;
  ll L[K], R[K];
  vector<ll> p;
  for (ll i = 0; i < K; i++) {
    cin >> L[i] >> R[i];
    for (ll j = L[i]; j <= R[i]; j++) {
      p.push_back(j);
    }
  }
  sort(p.begin(), p.end());
  ll m[N + 1];
  ll ans = 0;
  m[1] = 1;
  for (ll num = 2; num < N + 1; num++) {
    m[num] = 0;
    bool ok = false;
    for (ll i = 0; i < p.size(); i++) {
      if (p[i] <= num - 1) {
        m[num] += m[num - p[i]] % M;
        m[num] = m[num] % M;
      } else {
        break;
      }
    }
  }
  cout << m[N] << endl;
}

#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>

using namespace std;
typedef long long ll;
const ll M = 998244353;

int main() {
  ll N, K;
  cin >> N >> K;
  ll L[K], R[K];
  // vector<ll> p;
  for (ll i = 0; i < K; i++) {
    cin >> L[i] >> R[i];
  }
  ll a[N + 1];
  ll f[N + 1];
  for (ll i = 0; i < N + 1; i++) {
    f[i] = 0;
    a[0] = 0;
  }
  f[1] = 1;
  a[1] = 1;
  for (ll i = 0; i < N + 1; i++) {
    for (ll j = 0; j < K; j++) {
      ll li = i - R[j];
      ll ri = i - L[j];
      if (ri < 0)
        continue;
      if (li < 1)
        li = 1;
      f[i] += (a[ri] - a[li - 1]) % M;
    }
    a[i] = a[i - 1] + f[i];
  }

  cout << f[N] % M << endl;
}


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

#define FAST_IO                                                                \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);

#define ll long long
#define ull unsigned long long
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>

#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define forab(i, a, b) for (int i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
#define trav(i, x) for (auto &i : x)
#define endl cout << "\\n";
// const int mod = 1e9+7;
const int maxn = 2e5 + 7;
int factors[maxn];
ll mod = 998244353;
int main() {
  FAST_IO;
  ll n, x, y, k;
  cin >> n >> k;
  set<int> s;
  for (int i = 0; i < k; i++) {
    cin >> x >> y;
    for (int j = x; j <= y; j++)
      s.insert(j);
  }
  vector<ll> dp(maxn, 0);
  dp[0] = 0;
  dp[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (auto it = s.begin(); it != s.end(); it++) {
      // cout<<*it;
      if (i - *it >= 1)
        dp[i] = (dp[i] + dp[i - *it]) % mod;
    }
  }

  cout << dp[n] % mod;
  return 0;
}

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

#define FAST_IO                                                                \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);

#define ll long long
#define ull unsigned long long
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>

#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define forab(i, a, b) for (int i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
#define trav(i, x) for (auto &i : x)
#define endl cout << "\\n";
// const int mod = 1e9+7;
const int maxn = 2e5 + 7;
int factors[maxn];
ll mod = 998244353;
int main() {
  FAST_IO;
  ll n, x, y, k;
  cin >> n >> k;
  int arr[k][2];
  for (int i = 0; i < k; i++) {
    cin >> arr[i][0] >> arr[i][1];
  }
  vector<ll> dp(maxn, 0);
  dp[0] = 1;
  dp[1] = -1;
  for (int i = 0; i <= n; i++) {
    if (i > 0)
      dp[i] = (dp[i] + dp[i - 1]) % mod;
    for (auto it = 0; it < k; it++) {

      int a = arr[it][0];
      int b = arr[it][1];

      if (a + i < n)
        dp[i + a] = (dp[i + a] + dp[i]) % mod;
      if (b + 1 + i < n)
        dp[i + b + 1] = (dp[i + b + 1] - dp[i] + mod) % mod;
    }
  }

  cout << dp[n - 1] % mod;
  return 0;
}


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

using ll = long long;
using P = pair<ll, ll>;

const ll MOD = 998244353;
const ll INF = 1ll << 60;

#define FOR(i, a, b) for (ll i = (a); i < (ll)(b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) (v).begin(), (v).end()
#define DEBUG(x) ;
#define DEBUG(x) std::cerr << #x << " : " << (x) << std::endl;

int dx[4]{0, 1, 0, -1};
int dy[4]{1, 0, -1, 0};

ll dp[100000 * 2 + 10]{};

int main(int argc, char **argv) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll N, K;
  cin >> N >> K;
  dp[1] = 1;
  vector<ll> L(N), R(N);
  REP(i, K) cin >> L[i] >> R[i];
  vector<ll> S;
  REP(i, K) {
    for (ll d = L[i]; d <= R[i]; ++d)
      S.push_back(d);
  }

  for (ll i = 1; i < N; ++i) {
    for (auto s : S)
      if (i + s <= N)
        (dp[i + s] += dp[i]) %= MOD;
  }

  std::cout << dp[N] << std::endl;
  return 0;
}

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

using ll = long long;
using P = pair<ll, ll>;

const ll MOD = 998244353;
const ll INF = 1ll << 60;

#define FOR(i, a, b) for (ll i = (a); i < (ll)(b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) (v).begin(), (v).end()
#define DEBUG(x) ;
#define DEBUG(x) std::cerr << #x << " : " << (x) << std::endl;

int dx[4]{0, 1, 0, -1};
int dy[4]{1, 0, -1, 0};

template <typename T> struct BIT {
  int n;            // 要素数
  vector<T> bit[2]; // データの格納先
  BIT(int n_) { init(n_); }
  void init(int n_) {
    n = n_ + 1;
    for (int p = 0; p < 2; p++)
      bit[p].assign(n, 0);
  }
  void add_sub(int p, int i, T x) {
    for (int idx = i; idx < n; idx += (idx & -idx)) {
      (bit[p][idx] += x) %= MOD;
    }
  }
  void add(int l, int r, T x) { // [l,r) に加算
    add_sub(0, l, -x * (l - 1));
    add_sub(0, r, x * (r - 1));
    add_sub(1, l, x);
    add_sub(1, r, -x);
  }
  T sum_sub(int p, int i) {
    T s(0);
    for (int idx = i; idx > 0; idx -= (idx & -idx)) {
      (s += bit[p][idx]) %= MOD;
    }
    return s;
  }
  T sum(int i) {
    ll res = (sum_sub(1, i) * i) % MOD;
    return (res + sum_sub(0, i)) % MOD;
  }
};

int main(int argc, char **argv) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  BIT<ll> bt(2 * 100000 + 10);
  bt.add(1, 2, 1);
  ll N, K;
  cin >> N >> K;

  vector<ll> L(N), R(N);
  REP(i, K) cin >> L[i] >> R[i], R[i]++;
  REP(j, N) {
    REP(i, K) {
      bt.add(min(j + L[i], N + 1), min(j + R[i], N + 1),
             bt.sum(j) - bt.sum(j - 1));
    }
  }

  std::cout << (bt.sum(N) - bt.sum(N - 1) + MOD) % MOD << std::endl;
  return 0;
}


// {{{ by unolight
#pragma region
#include <bits/stdc++.h>
#include <unistd.h>
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wunused-function"
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define RALL(x) rbegin(x), rend(x)
#define REP(i, n) for (int i = 0; i < int(n); i++)
#define REP1(i, a, b) for (int i = (a); i <= int(b); i++)
#define MP make_pair
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef pair<int, int> PII;
typedef vector<int> VI;

namespace {
namespace unolight {
// Read Input
template <class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%" PRId64, &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template <class T, class... U> void R(T &head, U &...tail) {
  _R(head);
  R(tail...);
}
// Write Output
template <class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%" PRId64, x); }
void _W(const double &x) { printf("%.16f\\n", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template <class T> void _W(const vector<T> &x) {
  for (auto i = x.begin(); i != x.end(); _W(*i++))
    if (i != x.cbegin())
      putchar(' ');
}
void W() {}
template <class T, class... U> void W(const T &head, const U &...tail) {
  _W(head);
  putchar(sizeof...(tail) ? ' ' : '\\n');
  W(tail...);
}

#ifdef UNOLIGHT
#include "dump.hpp"
#else
#define dump(...)
#endif

template <class T> inline bool chmax(T &a, const T &b) {
  return b > a ? a = b, true : false;
}
template <class T> inline bool chmin(T &a, const T &b) {
  return b < a ? a = b, true : false;
}
template <class T> using MaxHeap = priority_queue<T>;
template <class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template <class T, class F = less<T>> void sort_uniq(vector<T> &v, F f = F()) {
  sort(begin(v), end(v), f);
  v.resize(unique(begin(v), end(v)) - begin(v));
}
#pragma endregion
// }}}

// {{{ ModInt
template <int _MOD> struct ModInt {
  static const auto MOD = _MOD;
  template <class T>
  using integral_only = typename enable_if<is_integral<T>::value>::type;

  int x;
  constexpr ModInt() : x() {}

  template <class T, integral_only<T> * = nullptr> ModInt(T _x = 0) {
    x = _x % MOD;
    if (x < 0)
      x += MOD;
  }
  ModInt operator-() const { return {x == 0 ? 0 : MOD - x}; }
  ModInt &operator+=(const ModInt a) {
    if ((x += a.x) >= MOD)
      x -= MOD;
    return *this;
  }
  ModInt &operator-=(const ModInt a) {
    if ((x += MOD - a.x) >= MOD)
      x -= MOD;
    return *this;
  }
  ModInt &operator*=(const ModInt a) {
    x = (long long)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 inv() const {
    // for prime MOD
    return pow(MOD - 2);
  }
  ModInt inv2() const {
    // work for non-prime MOD if gcd(x,MOD) = 1
    int a = x, b = MOD, u = 1, v = 0;
    while (b != 0) {
      int t = a / b;
      a -= t * b;
      u -= t * v;
      swap(a, b);
      swap(u, v);
    }
    return u;
  }
  template <class T, integral_only<T> * = nullptr> ModInt pow(T t) const {
    ModInt r = 1, p = *this;
    while (t) {
      if (t & 1)
        r *= p;
      p *= p;
      t >>= 1;
    }
    return r;
  }

  bool operator==(ModInt rhs) const { return x == rhs.x; }
  bool operator!=(ModInt rhs) const { return x != rhs.x; }
  bool operator<(ModInt rhs) const { return x < rhs.x; }
  bool operator<=(ModInt rhs) const { return x <= rhs.x; }
  bool operator>(ModInt rhs) const { return x > rhs.x; }
  bool operator>=(ModInt rhs) const { return x >= rhs.x; }

  friend string to_string(ModInt i) { return to_string(i.x); }
  friend istream &operator>>(istream &i, ModInt &a) { return i >> a.x; }
  friend ostream &operator<<(ostream &o, const ModInt &a) { return o << a.x; }
};

const int MOD = 998244353;
using mint = ModInt<MOD>;
// }}}

void main() {
  int n, k;
  R(n, k);
  vector<mint> dp(n * 2, 0);
  vector<PII> a(k);
  for (int i = 0; i < k; i++) {
    R(a[i].first, a[i].second);
  }
  dp[0] = 1;
  mint sum = 0;
  for (int i = 0; i < n; i++) {
    // if ( dp[i]==0 ) continue;
    sum += dp[i];
    for (int j = 0; j < k; j++) {
      int l = a[j].first, r = a[j].second;
      dp[i + l] += sum;
      dp[i + r + 1] -= sum;
    }
    // W(dp);
  }
  W(dp[n - 1]);
}

} // namespace unolight
} // namespace
int main() {
  unolight::main();
  return 0;
}
// }}}

// {{{ by unolight
#pragma region
#include <bits/stdc++.h>
#include <unistd.h>
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wunused-function"
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define RALL(x) rbegin(x), rend(x)
#define REP(i, n) for (int i = 0; i < int(n); i++)
#define REP1(i, a, b) for (int i = (a); i <= int(b); i++)
#define MP make_pair
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef pair<int, int> PII;
typedef vector<int> VI;

namespace {
namespace unolight {
// Read Input
template <class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%" PRId64, &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template <class T, class... U> void R(T &head, U &...tail) {
  _R(head);
  R(tail...);
}
// Write Output
template <class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%" PRId64, x); }
void _W(const double &x) { printf("%.16f\\n", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template <class T> void _W(const vector<T> &x) {
  for (auto i = x.begin(); i != x.end(); _W(*i++))
    if (i != x.cbegin())
      putchar(' ');
}
void W() {}
template <class T, class... U> void W(const T &head, const U &...tail) {
  _W(head);
  putchar(sizeof...(tail) ? ' ' : '\\n');
  W(tail...);
}

#ifdef UNOLIGHT
#include "dump.hpp"
#else
#define dump(...)
#endif

template <class T> inline bool chmax(T &a, const T &b) {
  return b > a ? a = b, true : false;
}
template <class T> inline bool chmin(T &a, const T &b) {
  return b < a ? a = b, true : false;
}
template <class T> using MaxHeap = priority_queue<T>;
template <class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template <class T, class F = less<T>> void sort_uniq(vector<T> &v, F f = F()) {
  sort(begin(v), end(v), f);
  v.resize(unique(begin(v), end(v)) - begin(v));
}
#pragma endregion
// }}}

// {{{ ModInt
template <int _MOD> struct ModInt {
  static const auto MOD = _MOD;
  template <class T>
  using integral_only = typename enable_if<is_integral<T>::value>::type;

  int x;
  constexpr ModInt() : x() {}

  template <class T, integral_only<T> * = nullptr> ModInt(T _x = 0) {
    x = _x % MOD;
    if (x < 0)
      x += MOD;
  }
  ModInt operator-() const { return {x == 0 ? 0 : MOD - x}; }
  ModInt &operator+=(const ModInt a) {
    if ((x += a.x) >= MOD)
      x -= MOD;
    return *this;
  }
  ModInt &operator-=(const ModInt a) {
    if ((x += MOD - a.x) >= MOD)
      x -= MOD;
    return *this;
  }
  ModInt &operator*=(const ModInt a) {
    x = (long long)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 inv() const {
    // for prime MOD
    return pow(MOD - 2);
  }
  ModInt inv2() const {
    // work for non-prime MOD if gcd(x,MOD) = 1
    int a = x, b = MOD, u = 1, v = 0;
    while (b != 0) {
      int t = a / b;
      a -= t * b;
      u -= t * v;
      swap(a, b);
      swap(u, v);
    }
    return u;
  }
  template <class T, integral_only<T> * = nullptr> ModInt pow(T t) const {
    ModInt r = 1, p = *this;
    while (t) {
      if (t & 1)
        r *= p;
      p *= p;
      t >>= 1;
    }
    return r;
  }

  bool operator==(ModInt rhs) const { return x == rhs.x; }
  bool operator!=(ModInt rhs) const { return x != rhs.x; }
  bool operator<(ModInt rhs) const { return x < rhs.x; }
  bool operator<=(ModInt rhs) const { return x <= rhs.x; }
  bool operator>(ModInt rhs) const { return x > rhs.x; }
  bool operator>=(ModInt rhs) const { return x >= rhs.x; }

  friend string to_string(ModInt i) { return to_string(i.x); }
  friend istream &operator>>(istream &i, ModInt &a) { return i >> a.x; }
  friend ostream &operator<<(ostream &o, const ModInt &a) { return o << a.x; }
};

const int MOD = 998244353;
using mint = ModInt<MOD>;
// }}}

void main() {
  int n, k;
  R(n, k);
  vector<mint> dp(n * 2, 0);
  vector<PII> a(k);
  for (int i = 0; i < k; i++) {
    R(a[i].first, a[i].second);
  }
  dp[0] = 1;
  mint sum = 0;
  for (int i = 0; i < n; i++) {
    // if ( dp[i]==0 ) continue;
    sum += dp[i];
    for (int j = 0; j < k; j++) {
      int l = a[j].first, r = a[j].second;
      if (i + l <= n)
        dp[i + l] += sum;
      if (i + r + 1 <= n)
        dp[i + r + 1] -= sum;
    }
    // W(dp);
  }
  W(dp[n - 1]);
}

} // namespace unolight
} // namespace
int main() {
  unolight::main();
  return 0;
}
// }}}


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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define RREP(i, m, n) for (int i = (int)((n)-1); i >= m; i--)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) RREP(i, 0, n)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define fi first
#define se second
#define debug(...)                                                             \\
  {                                                                            \\
    cerr << "[L" << __LINE__ << "] ";                                          \\
    _debug(__VA_ARGS__);                                                       \\
  }

template <typename T> string join(const vector<T> &v, string del = ", ") {
  stringstream s;
  for (auto x : v)
    s << del << x;
  return s.str().substr(del.size());
}
template <typename T> ostream &operator<<(ostream &o, const vector<T> &v) {
  if (v.size())
    o << "[" << join(v) << "]";
  return o;
}
template <typename T>
ostream &operator<<(ostream &o, const vector<vector<T>> &vv) {
  int l = vv.size();
  if (l) {
    o << endl;
    rep(i, l) o << (i == 0 ? "[ " : ",\\n  ") << vv[i]
                << (i == l - 1 ? " ]" : "");
  }
  return o;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &o, const pair<T1, T2> &p) {
  return o << "(" << p.first << ", " << p.second << ")";
}
inline void _debug() { cerr << endl; }
template <class First, class... Rest>
void _debug(const First &first, const Rest &...rest) {
  cerr << first << " ";
  _debug(rest...);
}

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

const double PI = (1 * acos(0.0));
const double EPS = 1e-9;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const ll mod = 1e9 + 7;

inline void finput(string filename) { freopen(filename.c_str(), "r", stdin); }

int main() {
  ios_base::sync_with_stdio(0);
  // finput("./input");
  int n, k;
  cin >> n >> k;
  set<int> s;
  rep(i, k) {
    int l, r;
    cin >> l >> r;
    REP(x, l, r + 1) s.insert(x);
  }

  vl dp(n);
  dp[0] = 1ll;
  REP(i, 1, n) for (auto x : s) {
    if (i - x >= 0)
      dp[i] += dp[i - x];
    dp[i] %= 998244353ll;
  }
  cout << dp[n - 1] << endl;
  return 0;
}

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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define RREP(i, m, n) for (int i = (int)((n)-1); i >= m; i--)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) RREP(i, 0, n)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define fi first
#define se second
#define debug(...)                                                             \\
  {                                                                            \\
    cerr << "[L" << __LINE__ << "] ";                                          \\
    _debug(__VA_ARGS__);                                                       \\
  }

template <typename T> string join(const vector<T> &v, string del = ", ") {
  stringstream s;
  for (auto x : v)
    s << del << x;
  return s.str().substr(del.size());
}
template <typename T> ostream &operator<<(ostream &o, const vector<T> &v) {
  if (v.size())
    o << "[" << join(v) << "]";
  return o;
}
template <typename T>
ostream &operator<<(ostream &o, const vector<vector<T>> &vv) {
  int l = vv.size();
  if (l) {
    o << endl;
    rep(i, l) o << (i == 0 ? "[ " : ",\\n  ") << vv[i]
                << (i == l - 1 ? " ]" : "");
  }
  return o;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &o, const pair<T1, T2> &p) {
  return o << "(" << p.first << ", " << p.second << ")";
}
inline void _debug() { cerr << endl; }
template <class First, class... Rest>
void _debug(const First &first, const Rest &...rest) {
  cerr << first << " ";
  _debug(rest...);
}

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

const double PI = (1 * acos(0.0));
const double EPS = 1e-9;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const ll mod = 998244353;

inline void finput(string filename) { freopen(filename.c_str(), "r", stdin); }

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 {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint &a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint &a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll 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 {
    mint res(*this);
    return res /= a;
  }
  friend ostream &operator<<(ostream &os, const mint &m) {
    os << m.x;
    return os;
  }
};

template <typename T> struct BIT {
  int n;
  vector<T> dat;
  BIT(int n) : n(n), dat(n + 1, 0) {}
  void add(int x, T val) {
    for (int i = x + 1; i <= n; i += (i & -i))
      dat[i] += val;
  }
  T sum(int x) {
    T ret = 0;
    for (int i = x + 1; i > 0; i -= (i & -i))
      ret += dat[i];
    return ret;
  }
  T sum(int a, int b) { return sum(b) - sum(a - 1); }
};

int main() {
  ios_base::sync_with_stdio(0);
  // finput("./input");
  int n, k;
  cin >> n >> k;
  vector<pii> s;
  rep(i, k) {
    int l, r;
    cin >> l >> r;
    s.emplace_back(l, r);
  }

  BIT<mint> dp(n + 1);
  dp.add(0, 1);
  dp.add(1, -1);
  rep(i, n) {
    for (auto p : s) {
      int l = p.fi, r = p.se;
      mint d = dp.sum(i);
      dp.add(i + l, d);
      dp.add(min(i + r + 1, n), -d);
    }
  }
  cout << dp.sum(n - 1) << endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;

ll N, K, count1 = 0;
stack<ll> rote;
vector<ll> T;
void ST(ll sum) {

  if (sum == N) {
    count1++;
    return;
  }
  if (sum > N)
    return;
  for (ll i = 0; i < T.size(); i++) {

    ST(sum + T[i]);
  }
  // ST(sum);

  return;
}

int main() {

  cin >> N >> K;
  set<ll> tile;

  for (ll i = 0; i < K; i++) {

    ll s1, s2;
    cin >> s1 >> s2;
    for (ll j = s1; j <= s2; j++)
      tile.insert(j);
  }

  for (ll i : tile)
    T.push_back(i);
  ST(1);

  cout << count1 << endl;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;

ll N, K;
const ll mm = 998244353;
int main() {

  cin >> N >> K;

  vector<pair<ll, ll>> tile(K);
  for (ll i = 0; i < K; i++)
    cin >> tile[i].first >> tile[i].second;
  vector<ll> Msum(N + 1, 0);
  Msum[1] = 1;
  for (ll i = 2; i <= N; i++) {

    for (ll j = 0; j < K; j++) {

      ll s1 = i - tile[j].first;
      ll s2 = i - tile[j].second;
      if (s1 <= 0 && s2 <= 0)
        continue;
      if (s2 <= 0 && s1 > 0)
        s2 = 1;
      Msum[i] += Msum[s1] - Msum[s2 - 1];
      if (Msum[i] < 0)
        Msum[i] += mm;
      Msum[i] %= mm;
    }
    Msum[i] += Msum[i - 1];
    Msum[i] %= mm;
  }

  cout << (Msum[N] - Msum[N - 1] + mm) % mm << endl;
}


//
#include <bits/stdc++.h>

using namespace std;

#define PB push_back
#define f first
#define s second
#define what_is(x) cerr << #x << " is " << x << endl;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

const int INF = 1000000007;
const int MOD = 998244353;

int bit[200005];
int n, k;
int upd(int x, int val) {
  for (; x <= n; x += x & -x) {
    bit[x] = (bit[x] + val) % MOD;
  }
}

int get(int x) {
  int res = 0;
  for (; x > 0; x -= x & -x) {
    res = (res + bit[x]) % MOD;
  }
  return res;
}
void solve_test() {
  cin >> n >> k;
  upd(1, 1);
  vector<pii> v;
  for (int i = 0; i < k; i++) {
    int l, r;
    cin >> l >> r;
    v.PB({l, r});
  }
  sort(v.begin(), v.end());
  for (int i = 2; i <= n; i++) {
    int lo = 0, hi = 0;
    for (int j = 0; j < k; j++) {
      lo = max(lo, v[j].f);
      hi = v[j].s;
      if (lo > hi)
        continue;
      if (lo >= i)
        break;
      //            what_is(lo);
      //            what_is(hi);
      hi = min(i - 1, hi);
      int res = (MOD + get(i - lo) - get(i - hi - 1)) % MOD;
      upd(i, res);
      lo = hi + 1;
    }
    // cout << i << " " << get(i) << "\\n";
  }
  cout << get(n) - get(n - 1) << "\\n";
}

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int tests;
  tests = 1;
  // cin >> tests;
  while (tests--) {
    solve_test();
  }
  return 0;
}

//
#include <bits/stdc++.h>

using namespace std;

#define PB push_back
#define f first
#define s second
#define what_is(x) cerr << #x << " is " << x << endl;
#define int long long

const int INF = 1000000007;
const int MOD = 998244353;

int bit[200005];
int n, k;
void upd(int x, int val) {
  for (; x <= n; x += x & -x) {
    bit[x] = (bit[x] + val) % MOD;
  }
}

int get(int x) {
  int res = 0;
  for (; x > 0; x -= x & -x) {
    res = (res + bit[x]) % MOD;
  }
  return res;
}
void solve_test() {
  cin >> n >> k;
  upd(1, 1);
  vector<pair<int, int>> v;
  for (int i = 0; i < k; i++) {
    int l, r;
    cin >> l >> r;
    v.PB({l, r});
  }
  sort(v.begin(), v.end());
  for (int i = 2; i <= n; i++) {
    int lo = 0, hi = 0;
    for (int j = 0; j < k; j++) {
      lo = v[j].f;
      hi = v[j].s;
      if (lo >= i)
        break;
      //            what_is(lo);
      //            what_is(hi);
      hi = min(i - 1, hi);
      int res = (MOD + get(i - lo) - get(i - hi - 1)) % MOD;
      upd(i, res);
    }
    // cout << i << " " << get(i) << "\\n";
  }
  cout << (MOD + get(n) - get(n - 1)) % MOD << "\\n";
}

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int tests;
  tests = 1;
  // cin >> tests;
  while (tests--) {
    solve_test();
  }
  return 0;
}


#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
typedef long long ll;

const int mod = 998244353;
vector<ll> m;

ll dp[220000];
ll rec(ll n) {
  if (dp[n] > 0)
    return dp[n];
  if (n == 0)
    return 1;

  ll ret = 0;
  for (auto step : m) {
    if (n - step < 0)
      continue;

    ret = (ret + rec(n - step)) % mod;
  }

  return dp[n] = ret;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  ll n, k;
  cin >> n >> k;

  rep(i, k) {
    ll l, r;
    cin >> l >> r;

    for (ll j = l; j <= r; ++j)
      m.push_back(j);
  }

  cout << rec(n - 1) << endl;

  return 0;
}

#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
typedef long long ll;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  int n, k;
  cin >> n >> k;
  vector<int> l(k), r(k);
  rep(i, k) cin >> l[i] >> r[i];

  const int mod = 998244353;
  vector<int> dp(n + 1, 0), dps(n + 1, 0);
  dp[1] = dps[1] = 1;

  for (int i = 2; i < n + 1; ++i) {
    rep(j, k) {
      dp[i] = ((dp[i] + (i - l[j] >= 0 ? dps[i - l[j]] : 0) % mod) % mod -
               (i - (r[j] + 1) >= 0 ? dps[i - (r[j] + 1)] : 0) % mod + mod) %
              mod;
    }
    dps[i] = dps[i - 1] + dp[i];
    dps[i] %= mod;
  }

  // rep(i, n+1) cout << dp[i] << " ";
  // cout << endl;

  cout << dp[n] << endl;

  return 0;
}