#pragma GCC optimize("O3") // コンパイラ最適化用

// #define _GLIBCXX_DEBUG //配列に[]でアクセス時のエラー表示
#include <algorithm> //sort,二分探索,など
#include <bitset>    //固定長bit集合
#include <cassert>   //assert(p)で，not pのときにエラー
#include <cctype>
#include <chrono>  //実行時間計測
#include <cmath>   //pow,logなど
#include <complex> //複素数
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional> //sortのgreater
#include <iomanip>    //setprecision(浮動小数点の出力の誤差)
#include <ios>        // std::left, std::right
#include <iostream>   //入出力
#include <iterator>   //集合演算(積集合,和集合,差集合など)
#include <map>
#include <numeric> //iota(整数列の生成),gcdとlcm,accumulate
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility> //pair
#include <vector>
using namespace std;
typedef long long LL;
typedef long double LD;

#define ALL(x) x.begin(), x.end()
#define SIZE(x) LL(x.size()) // sizeをsize_tからLLに直しておく
const long long INF = 1e12;
const int MOD = 998244353;
#define MAXR 100000 // 10^5:配列の最大のrange(素数列挙などで使用)
// 略記
#define UMAP unordered_map
#define USET unordered_set
#define FF first
#define SS second
#define int long long
#define LD long double
#define PII pair<int, int>
#define PB push_back
#define MP make_pair
#define SZ(x) (int)((x).size())
#define VI vector<int>
#define VVI vector<vector<int>>
#define VLL vector<LL>
#define VVLL vector<vector<LL>>

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPD(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < (int)(b); i++)
#define FORD(i, a, b) for (int i = (int)(b)-1; i >= (int)a; i--)

const unsigned int BIT_FLAG_0 = (1 << 0); // 0000 0000 0000 0001
const unsigned int BIT_FLAG_1 = (1 << 1); // 0000 0000 0000 0010
const unsigned int BIT_FLAG_2 = (1 << 2); // 0000 0000 0000 0100
const unsigned int BIT_FLAG_3 = (1 << 3); // 0000 0000 0000 1000
const unsigned int BIT_FLAG_4 = (1 << 4); // 0000 0000 0001 0000
const unsigned int BIT_FLAG_5 = (1 << 5); // 0000 0000 0010 0000
const unsigned int BIT_FLAG_6 = (1 << 6); // 0000 0000 0100 0000
const unsigned int BIT_FLAG_7 = (1 << 7); // 0000 0000 1000 0000
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1},
          Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};

// https://qiita.com/Lily0727K/items/06cb1d6da8a436369eed#c%E3%81%A7%E3%81%AE%E5%AE%9F%E8%A3%85
void print() { cout << "\\n"; }

template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) {
  cout << head;
  if (sizeof...(tail) != 0)
    cout << " ";
  print(forward<Tail>(tail)...);
}

template <class T> void print(vector<T> &vec) {
  for (auto &a : vec) {
    cout << a;
    if (&a != &vec.back())
      cout << " ";
  }
  cout << "\\n";
}

template <class T> void print(set<T> &set) {
  for (auto &a : set) {
    cout << a << " ";
  }
  cout << "\\n";
}

template <class T> void print(vector<vector<T>> &df) {
  for (auto &vec : df) {
    print(vec);
  }
}
long long power(long long x, long long n) {
  // O(logn)
  // https://algo-logic.info/calc-pow/#toc_id_1_2
  long long ret = 1;
  while (n > 0) {
    if (n & 1)
      ret *= x; // n の最下位bitが 1 ならば x^(2^i) をかける
    x *= x;
    n >>= 1; // n を1bit 左にずらす
  }
  return ret;
}
long long comb(int n, int k) {
  vector<vector<long long>> v(n + 1, vector<long long>(n + 1, 0));

  for (int i = 0; i < SZ(v); i++) {
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for (int k = 1; k < SZ(v); k++) {
    for (int j = 1; j < k; j++) {
      v[k][j] = (v[k - 1][j - 1] + v[k - 1][j]);
    }
  }
  return v[n][k];
}
void add(long long &a, long long b) {
  a += b;
  if (a >= MOD)
    a -= MOD;
}
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;
}

__attribute__((constructor)) void faster_io() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
}

int n, k;
vector<PII> segs;
signed main() {
  cin >> n >> k;
  REP(ki, k) {
    int l, r;
    cin >> l >> r;
    segs.PB(MP(l, r));
  }
  sort(ALL(segs));

  VI dp(n + 10, 0);
  dp[1] = 1;
  FOR(ni, 1, n) {
    REP(ki, k) {
      bool ng = false;
      int l = segs[ki].FF, r = segs[ki].SS;
      FOR(di, l, r + 1) {
        if (ni + di > n) {
          ng = true;
          break;
        }
        dp[ni + di] += dp[ni] % MOD;
        dp[ni + di] % MOD;
      }
      if (ng) {
        break;
      }
    }
  }
  print(dp[n] % MOD);
  return 0;
}

#pragma GCC optimize("O3") // コンパイラ最適化用

// #define _GLIBCXX_DEBUG //配列に[]でアクセス時のエラー表示
#include <algorithm> //sort,二分探索,など
#include <bitset>    //固定長bit集合
#include <cassert>   //assert(p)で，not pのときにエラー
#include <cctype>
#include <chrono>  //実行時間計測
#include <cmath>   //pow,logなど
#include <complex> //複素数
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional> //sortのgreater
#include <iomanip>    //setprecision(浮動小数点の出力の誤差)
#include <ios>        // std::left, std::right
#include <iostream>   //入出力
#include <iterator>   //集合演算(積集合,和集合,差集合など)
#include <map>
#include <numeric> //iota(整数列の生成),gcdとlcm,accumulate
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility> //pair
#include <vector>
using namespace std;
typedef long long LL;
typedef long double LD;

#define ALL(x) x.begin(), x.end()
#define SIZE(x) LL(x.size()) // sizeをsize_tからLLに直しておく
const long long INF = 1e12;
const int MOD = 998244353;
#define MAXR 100000 // 10^5:配列の最大のrange(素数列挙などで使用)
// 略記
#define UMAP unordered_map
#define USET unordered_set
#define FF first
#define SS second
#define int long long
#define LD long double
#define PII pair<int, int>
#define PB push_back
#define MP make_pair
#define SZ(x) (int)((x).size())
#define VI vector<int>
#define VVI vector<vector<int>>
#define VLL vector<LL>
#define VVLL vector<vector<LL>>

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPD(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < (int)(b); i++)
#define FORD(i, a, b) for (int i = (int)(b)-1; i >= (int)a; i--)

const unsigned int BIT_FLAG_0 = (1 << 0); // 0000 0000 0000 0001
const unsigned int BIT_FLAG_1 = (1 << 1); // 0000 0000 0000 0010
const unsigned int BIT_FLAG_2 = (1 << 2); // 0000 0000 0000 0100
const unsigned int BIT_FLAG_3 = (1 << 3); // 0000 0000 0000 1000
const unsigned int BIT_FLAG_4 = (1 << 4); // 0000 0000 0001 0000
const unsigned int BIT_FLAG_5 = (1 << 5); // 0000 0000 0010 0000
const unsigned int BIT_FLAG_6 = (1 << 6); // 0000 0000 0100 0000
const unsigned int BIT_FLAG_7 = (1 << 7); // 0000 0000 1000 0000
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1},
          Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};

// https://qiita.com/Lily0727K/items/06cb1d6da8a436369eed#c%E3%81%A7%E3%81%AE%E5%AE%9F%E8%A3%85
void print() { cout << "\\n"; }

template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) {
  cout << head;
  if (sizeof...(tail) != 0)
    cout << " ";
  print(forward<Tail>(tail)...);
}

template <class T> void print(vector<T> &vec) {
  for (auto &a : vec) {
    cout << a;
    if (&a != &vec.back())
      cout << " ";
  }
  cout << "\\n";
}

template <class T> void print(set<T> &set) {
  for (auto &a : set) {
    cout << a << " ";
  }
  cout << "\\n";
}

template <class T> void print(vector<vector<T>> &df) {
  for (auto &vec : df) {
    print(vec);
  }
}
long long power(long long x, long long n) {
  // O(logn)
  // https://algo-logic.info/calc-pow/#toc_id_1_2
  long long ret = 1;
  while (n > 0) {
    if (n & 1)
      ret *= x; // n の最下位bitが 1 ならば x^(2^i) をかける
    x *= x;
    n >>= 1; // n を1bit 左にずらす
  }
  return ret;
}
long long comb(int n, int k) {
  vector<vector<long long>> v(n + 1, vector<long long>(n + 1, 0));

  for (int i = 0; i < SZ(v); i++) {
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for (int k = 1; k < SZ(v); k++) {
    for (int j = 1; j < k; j++) {
      v[k][j] = (v[k - 1][j - 1] + v[k - 1][j]);
    }
  }
  return v[n][k];
}
void add(long long &a, long long b) {
  a += b;
  if (a >= MOD)
    a -= MOD;
}
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;
}

__attribute__((constructor)) void faster_io() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
}
// modint: mod 計算を int を扱うように扱える構造体
// https://github.com/drken1215/algorithm/blob/master/MathCombinatorics/mod.cpp
// https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a

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;
  }
};

// 二項係数ライブラリ
template <class T> struct BiCoef {
  vector<T> fact_, inv_, finv_;
  constexpr BiCoef() {}
  constexpr BiCoef(int n) noexcept : fact_(n, 1), inv_(n, 1), finv_(n, 1) {
    init(n);
  }
  constexpr void init(int n) noexcept {
    fact_.assign(n, 1), inv_.assign(n, 1), finv_.assign(n, 1);
    int MOD = fact_[0].getmod();
    for (int i = 2; i < n; i++) {
      fact_[i] = fact_[i - 1] * i;
      inv_[i] = -inv_[MOD % i] * (MOD / i);
      finv_[i] = finv_[i - 1] * inv_[i];
    }
  }
  constexpr T com(int n, int k) const noexcept {
    if (n < k || n < 0 || k < 0)
      return 0;
    return fact_[n] * finv_[k] * finv_[n - k];
  }
  constexpr T fact(int n) const noexcept {
    if (n < 0)
      return 0;
    return fact_[n];
  }
  // 追加
  constexpr T perm(int n, int k) const noexcept {
    if (n < k || n < 0 || k < 0)
      return 0;
    return fact_[n] * finv_[k] * finv_[n - k] * fact_[k];
  }

  constexpr T inv(int n) const noexcept {
    if (n < 0)
      return 0;
    return inv_[n];
  }
  constexpr T finv(int n) const noexcept {
    if (n < 0)
      return 0;
    return finv_[n];
  }
};

using mint = Fp<MOD>;
BiCoef<mint> bc;
/*
int main() {
    long long N, M, K; cin >> N >> M >> K;
    bc.init(510000); // 忘れない！
    mint sum = 0;
    for (int i = 0; i <= N-1; ++i) {
        for (int j = 0; j <= M-1; ++j) {
            mint tmp = mint(N - i) * mint(M - j) * mint(i + j);
            modpow(mint(i),N); // 引数はllあるいはmintにして渡す
            if (i != 0 && j != 0) tmp *= 2;
            sum += tmp;
        }
    }
    cout << sum * bc.com(N*M-2, K-2) << endl;
}
*/
/**
 * @brief Dual-Segment-Tree(双対セグメント木)
 * @docs docs/dual-segment-tree.md
 */
template <typename OperatorMonoid, typename H> struct DualSegmentTree {
  int sz, height;
  vector<OperatorMonoid> lazy;
  const H h;
  const OperatorMonoid OM0;

  DualSegmentTree(int n, const H h, const OperatorMonoid &OM0)
      : h(h), OM0(OM0) {
    sz = 1;
    height = 0;
    while (sz < n)
      sz <<= 1, height++;
    lazy.assign(2 * sz, OM0);
  }

  inline void propagate(int k) {
    if (lazy[k] != OM0) {
      lazy[2 * k + 0] = h(lazy[2 * k + 0], lazy[k]);
      lazy[2 * k + 1] = h(lazy[2 * k + 1], lazy[k]);
      lazy[k] = OM0;
    }
  }

  inline void thrust(int k) {
    for (int i = height; i > 0; i--)
      propagate(k >> i);
  }

  void update(int a, int b, const OperatorMonoid &x) {
    thrust(a += sz);
    thrust(b += sz - 1);
    for (int l = a, r = b + 1; l < r; l >>= 1, r >>= 1) {
      if (l & 1)
        lazy[l] = h(lazy[l], x), ++l;
      if (r & 1)
        --r, lazy[r] = h(lazy[r], x);
    }
  }

  OperatorMonoid operator[](int k) {
    thrust(k += sz);
    return lazy[k];
  }
};

template <typename OperatorMonoid, typename H>
DualSegmentTree<OperatorMonoid, H>
get_dual_segment_tree(int N, const H &h, const OperatorMonoid &OM0) {
  return {N, h, OM0};
}

int n, k;
vector<PII> segs;
signed main() {
  cin >> n >> k;
  REP(ki, k) {
    int l, r;
    cin >> l >> r;
    segs.PB(MP(l, r));
  }
  // sort(ALL(segs));

  auto h = [](mint a, mint b) { return mint(a + b); };
  auto seg = get_dual_segment_tree(n + 10, h, mint(0));
  seg.update(1, 2, 1);

  FOR(ni, 1, n) {
    REP(ki, k) {
      int l = ni + segs[ki].FF, r = ni + segs[ki].SS;
      if (l > n) {
        continue;
      }
      if (r > n) {
        r = n;
      }

      seg.update(l, r + 1, seg[ni]); //
    }
  }
  print(seg[n]);
  return 0;
}


#include "bits/stdc++.h"
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> dp(2 * n, 0);
  ll wa = 0;

  vector<ll> l(k), r(k);
  rep(i, k) {
    cin >> l[i] >> r[i];
    ++r[i];
  }

  dp[1] = 1;
  ll mod = 998244353;

  rep(i, n + 1) {
    wa += dp[i];
    wa = wa % mod;
    rep(j, k) {
      dp[i + l[j]] += wa;
      dp[i + l[j]] = dp[i + l[j]] % mod;

      dp[i + r[j]] -= wa;
      dp[i + r[j]] = dp[i + r[j]] % mod;
    }
  }

  cout << dp[n] << endl;

  return 0;
}

#include "bits/stdc++.h"
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> dp(3 * n, 0);
  ll wa = 0;

  vector<ll> l(k), r(k);
  rep(i, k) {
    cin >> l[i] >> r[i];
    ++r[i];
  }

  dp[1] = 1;
  dp[2] = -1;
  ll mod = 998244353;

  rep(i, n + 1) {
    wa += dp[i];
    // cout << wa << endl;
    wa = wa % mod;
    rep(j, k) {
      dp[i + l[j]] += wa;
      dp[i + l[j]] = dp[i + l[j]] % mod;

      dp[i + r[j]] -= wa;
      dp[i + r[j]] = dp[i + r[j]] % mod;
    }
  }

  if (wa < 0) {
    wa += mod;
  }

  cout << wa << endl;

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<ll> vll;

#define PI (2 * acos(0.0))
#define eps 1e-9
#define pb push_back
#define endl "\\n"
#define watch(x) cout << (#x) << " is " << (x) << endl;
#define show(v)                                                                \\
  for (int fi = 0; fi < v.size(); fi++)                                        \\
    cout << v[fi] << " ";                                                      \\
  cout << endl;
#define showpair(v)                                                            \\
  for (int fi = 0; fi < v.size(); fi++)                                        \\
    cout << v[fi].first << " " << v[fi].second << endl;
#define ff first
#define ss second
#define fu cout << "lol" << endl;
#define precision(n) cout << fixed << setprecision(n);
#define lb lower_bound
#define up upper_bound
#define vscan                                                                  \\
  for (i = 0; i < n; i++) {                                                    \\
    cin >> in;                                                                 \\
    v.pb(in);                                                                  \\
  }
#define all(a) a.begin(), a.end()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define mem(a, val) memset(a, val, sizeof(a))
#define loop(i, n) for (i = 0; i < n; i++)
#define TC                                                                     \\
  ull T;                                                                       \\
  cin >> T;                                                                    \\
  while (T--)
#define IN(x)                                                                  \\
  { scanf("%d", &x); }
#define LL(x)                                                                  \\
  { scanf("%lld", &x); }
#define CC(x)                                                                  \\
  { scanf("%c", &x); }
#define pfl(x) printf("%d\\n", x)
#define pfll(x) printf("%lld\\n", x)
#define newl puts("")
#define space printf(" ")
#define MOD 1000000007
#define speed                                                                  \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);

const int N = 3e5;
ll dp[N];

int main() {
  int i = 0, j = 0, cs = 0, in;
  int n, k;
  cin >> n >> k;
  vi v;
  for (int i = 0; i < k; i++) {
    int a, b;
    cin >> a >> b;
    for (int j = a; j <= b; j++)
      v.pb(j);
  }
  dp[1] = 1;
  ll mod = 998244353;
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < v.size(); j++) {
      if (i - v[j] > 0)
        dp[i] += dp[i - v[j]], dp[i] %= mod;
    }
  }
  cout << dp[n] << endl;
  return 0;
}

#include <bits/stdc++.h>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<ll> vll;

#define PI (2 * acos(0.0))
#define eps 1e-9
#define pb push_back
#define endl "\\n"
#define watch(x) cout << (#x) << " is " << (x) << endl;
#define show(v)                                                                \\
  for (int fi = 0; fi < v.size(); fi++)                                        \\
    cout << v[fi] << " ";                                                      \\
  cout << endl;
#define showpair(v)                                                            \\
  for (int fi = 0; fi < v.size(); fi++)                                        \\
    cout << v[fi].first << " " << v[fi].second << endl;
#define ff first
#define ss second
#define fu cout << "lol" << endl;
#define precision(n) cout << fixed << setprecision(n);
#define lb lower_bound
#define up upper_bound
#define vscan                                                                  \\
  for (i = 0; i < n; i++) {                                                    \\
    cin >> in;                                                                 \\
    v.pb(in);                                                                  \\
  }
#define all(a) a.begin(), a.end()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define mem(a, val) memset(a, val, sizeof(a))
#define loop(i, n) for (i = 0; i < n; i++)
#define TC                                                                     \\
  ull T;                                                                       \\
  cin >> T;                                                                    \\
  while (T--)
#define IN(x)                                                                  \\
  { scanf("%d", &x); }
#define LL(x)                                                                  \\
  { scanf("%lld", &x); }
#define CC(x)                                                                  \\
  { scanf("%c", &x); }
#define pfl(x) printf("%d\\n", x)
#define pfll(x) printf("%lld\\n", x)
#define newl puts("")
#define space printf(" ")
#define MOD 998244353
#define speed                                                                  \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);

const int N = 3e5;
ll dp[N];
ll dpsum[N];

int main() {
  int i = 0, j = 0, cs = 0, in;
  int n, k;
  cin >> n >> k;
  vii v(k);
  for (int i = 0; i < k; i++) {
    cin >> v[i].ff >> v[i].ss;
  }
  dp[1] = dpsum[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < k; j++) {
      if (v[j].ff >= i)
        continue;
      int l = max(1, i - v[j].ss), r = i - v[j].ff;
      dp[i] += (dpsum[r] - dpsum[l - 1]);
      dp[i] = (dp[i] + MOD) % MOD;
    }
    dpsum[i] = dpsum[i - 1] + dp[i], dpsum[i] %= MOD;
  }
  cout << dp[n] << endl;
  return 0;
}


#pragma GCC optimize(                                                          \\
    "Ofast") // Comment optimisations for interactive problems (use endl)
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>

using namespace std;

#define fastio                                                                 \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);                                                                 \\
  cout << fixed;                                                               \\
  cout << setprecision(10);
#define randomINIT                                                             \\
  mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define all(x) (x).begin(), (x).end()
#define mset(x, val) memset(x, val, sizeof(x))
#define endl "\\n"
#define pb push_back
#define sym(s) s = "#" + s + "#";
#define mp make_pair
#define s second
#define f first
#define dline cerr << "///REACHED///\\n";
#define debv(a)                                                                \\
  for (auto it : a)                                                            \\
    cout << it << " ";                                                         \\
  cout << endl;
#define deb1(a) cout << a << endl;
#define deb2(a, b) cout << a << " " << b << endl;
#define deb3(a, b, c) cout << a << " " << b << " " << c << endl;
#define deb4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl;
#define uniq(a) a.resize(unique(a.begin(), a.end()) - a.begin());

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;

const ll MOD = 998244353;
const ll INF = 0x7f7f7f7f7f7f7f7f;
const int INFi = 0x7f7f7f7f;
const ll N = 3e+5 + 7;

vll adj[N];
ll vis[N] = {};
int dx8[] = {0, 1, 1, 1, 0, -1, -1, -1}, dy8[] = {1, 1, 0, -1, -1, -1, 0, 1};
int dx4[] = {0, 1, 0, -1}, dy4[] = {1, 0, -1, 0};

//<<-----Declare Variable Here------->>//
int t = 1;
ll n, k;
ll pre[N];
vll v;
ll dp[N];
//<<-----Implement Functions Here---->>//
ll func(ll ind) {
  if (ind == n)
    return 1;

  if (ind >= n + 1)
    return 0;

  if (dp[ind] != -1)
    return dp[ind];

  ll ans = 0;
  for (auto it : v)
    ans += func(ind + it);
  return dp[ind] = ans;
}

//<<-----Start of Main--------------->>//
void MAIN() {
  cin >> n >> k;
  for (ll i = 0; i <= n + 1; i++)
    dp[i] = -1;
  for (ll i = 1; i <= k; i++) {
    ll l, r;
    cin >> l >> r;
    pre[l]++;
    pre[r + 1]--;
  }
  for (ll i = 1; i <= n; i++)
    pre[i] += pre[i - 1];
  for (ll i = 1; i <= n; i++)
    if (pre[i] >= 1)
      v.pb(i);
  cout << func(1) % MOD;
}

int main() {
  fastio;
  randomINIT;

  // cin>>t;
  while (t--) {
    MAIN();
  }

#ifndef ONLINE_JUDGE
  cout << "\\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\\n";
#endif
}

#pragma GCC optimize(                                                          \\
    "Ofast") // Comment optimisations for interactive problems (use endl)
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>

using namespace std;

#define fastio                                                                 \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);                                                                 \\
  cout << fixed;                                                               \\
  cout << setprecision(10);
#define randomINIT                                                             \\
  mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define all(x) (x).begin(), (x).end()
#define mset(x, val) memset(x, val, sizeof(x))
#define endl "\\n"
#define pb push_back
#define sym(s) s = "#" + s + "#";
#define mp make_pair
#define s second
#define f first
#define dline cerr << "///REACHED///\\n";
#define debv(a)                                                                \\
  for (auto it : a)                                                            \\
    cout << it << " ";                                                         \\
  cout << endl;
#define deb1(a) cout << a << endl;
#define deb2(a, b) cout << a << " " << b << endl;
#define deb3(a, b, c) cout << a << " " << b << " " << c << endl;
#define deb4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl;
#define uniq(a) a.resize(unique(a.begin(), a.end()) - a.begin());

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;

const ll MOD = 998244353;
const ll INF = 0x7f7f7f7f7f7f7f7f;
const int INFi = 0x7f7f7f7f;
const ll N = 3e+5 + 7;

vll adj[N];
ll vis[N] = {};
int dx8[] = {0, 1, 1, 1, 0, -1, -1, -1}, dy8[] = {1, 1, 0, -1, -1, -1, 0, 1};
int dx4[] = {0, 1, 0, -1}, dy4[] = {1, 0, -1, 0};

//<<-----Declare Variable Here------->>//
int t = 1;
ll n, k;
ll l[15], r[15];
ll dp[N], pre[N];
//<<-----Implement Functions Here---->>//
ll add(ll a, ll b) { return (a % MOD + b % MOD) % MOD; }
ll mult(ll a, ll b) { return (a % MOD * b % MOD) % MOD; }
ll subt(ll a, ll b) { return (a % MOD - b % MOD + MOD) % MOD; }

//<<-----Start of Main--------------->>//
void MAIN() {
  cin >> n >> k;
  for (ll i = 1; i <= k; i++)
    cin >> l[i] >> r[i];
  dp[0] = 0;
  dp[1] = 1;

  for (ll i = 1; i <= n; i++) {
    for (ll j = 1; j <= k; j++) {
      ll l1 = max(i - l[j], ll(0));
      ll r1 = max(i - r[j], ll(1));
      dp[i] = add(dp[i], subt(pre[l1], pre[r1 - 1]));
    }
    pre[i] = add(pre[i], add(pre[i - 1], dp[i]));
    // for(ll i=1;i<=n;i++)cout<<dp[i]<<" ";cout<<endl;
    // for(ll i=1;i<=n;i++)cout<<pre[i]<<" ";cout<<endl;
  }

  cout << dp[n] << endl;
}

int main() {
  fastio;
  randomINIT;

  // cin>>t;
  while (t--) {
    MAIN();
  }

#ifndef ONLINE_JUDGE
  cout << "\\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\\n";
#endif
}


#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
const int N = 200010;
typedef pair<int, int> pii;
int a[N][2];
int cnt;
long long f[N];
vector<int> v;
pair<int, int> q[12];
const int mod = 998244353;
int main() {
  // get_prime(1000000);
  int n, k;
  cin >> n >> k;
  f[1] = 1;
  for (int i = 1; i <= k; i++) {
    int l, r;
    cin >> l >> r;
    q[i] = {l, r};
  }
  sort(q + 1, q + 1 + k);
  for (int i = 1; i <= k; i++)
    for (int j = q[i].first; j <= q[i].second; j++)
      v.push_back(j);
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < v.size(); j++) {
      if (i - v[j] <= 0)
        break;
      f[i] += f[i - v[j]];
      f[i] %= mod;
    }
  }
  cout << f[n] << endl;
  return 0;
}

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
const int N = 200010;
typedef pair<int, int> pii;
int k;
long long f[N];
vector<int> v;
pair<int, int> q[12];
long long tr[N];
int n;
int lowbit(int x) { return x & -x; }
const int mod = 998244353;
void add(int x, int d) {
  for (int i = x; i <= n; i += lowbit(i))
    tr[i] = (tr[i] + d) % mod;
}

int query(int x) {
  long long res = 0;
  for (int i = x; i; i -= lowbit(i))
    res = (res + tr[i]) % mod;
  return res;
}

int main() {
  // get_prime(1000000);
  cin >> n >> k;
  f[1] = 1;
  for (int i = 1; i <= k; i++) {
    int l, r;
    cin >> l >> r;
    q[i] = {l, r};
  }
  sort(q + 1, q + 1 + k);
  // v.push_back(0);
  for (int i = 1; i <= k; i++)
    for (int j = q[i].first; j <= q[i].second; j++)
      v.push_back(j);
  add(1, 1);
  for (int i = 2; i <= n; i++) {
    // int pos=lower_bound(v.begin(),v.end(),i)-v.begin();
    //   cout<<i<<' '<<pos<<' '<<v[pos]<<endl;
    // if(v[0]>i)
    //  continue;
    // if(i-v[pos-1]-1)
    // if(pos==0)  pos++;
    for (int j = 1; j <= k; j++) {
      int rr = i - q[j].first;
      int ll = i - q[j].second;
      if (rr <= 0)
        continue;
      ll = max(ll, 1);
      f[i] = (f[i] + (query(rr) - query(ll - 1)) % mod + mod) % mod;
    }
    add(i, f[i]);
  }
  cout << f[n] << endl;
  return 0;
}


#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
int main() {
  int N, K;
  cin >> N >> K;
  vector<int> ablestep;
  vector<int> HEX(N + 5, 0);
  while (K--) {
    int a, b;
    cin >> a >> b;
    for (; a <= b; a++)
      ablestep.push_back(a);
  }
  sort(ablestep.begin(), ablestep.end());
  HEX[1] = 1;
  for (int i = 1; i <= N; i++) {
    for (auto s : ablestep) {
      if (s >= i)
        break;
      HEX[i] += HEX[i - s];
      HEX[i] %= 998244353;
    }
  }
  cout << HEX[N] << '\\n';
}

#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
const int MOD = 998244353;
int main() {
  int N, K;
  cin >> N >> K;
  vector<pair<int, int>> ablestep;
  vector<int> dp(N + 5, 0), presum(N + 5, 0);
  while (K--) {
    int a, b;
    cin >> a >> b;
    ablestep.push_back({a, b});
  }
  dp[0] = 0;
  presum[0] = 0;
  dp[1] = 1;
  presum[1] = 1;
  for (int i = 1; i <= N; i++) {
    for (auto s : ablestep) {
      int l = i - s.second, r = i - s.first;
      if (l < 1)
        l = 1;
      if (l > r)
        continue;
      dp[i] += ((presum[r] - presum[l - 1]) + MOD) % MOD;

      dp[i] %= MOD;
    }
    presum[i] = (presum[i - 1] + dp[i]) % MOD;
  }
  cout << dp[N] % MOD << '\\n';
}


#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

using ll = long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr ll MOD = 998244353;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, k, l, r;
  cin >> n >> k;

  vector<int> v;
  for (int i = 0; i < k; ++i) {
    cin >> l >> r;
    for (int j = l; j <= r; ++j) {
      v.push_back(j);
    }
  }
  sort(v.begin(), v.end());
  int m = v.size();

  vector<ll> dp(n + 1, 0);
  dp[1] = 1LL;
  for (int i = 2; i <= n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (i - v[j] <= 0)
        continue;
      dp[i] += dp[i - v[j]];
      dp[i] %= MOD;
    }
  }

  cout << dp[n] << endl;
}

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

using ll = long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr ll MOD = 998244353;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, k, l, r;
  cin >> n >> k;

  vector<Pii> lr;
  for (int i = 0; i < k; ++i) {
    cin >> l >> r;
    lr.emplace_back(l, r);
  }

  vector<ll> dp(n + 1, 0);
  dp[1] = 1LL;
  for (int i = 2; i <= n; ++i) {
    dp[i - 1] += dp[i - 2];
    dp[i - 1] %= MOD;
    for (int j = 0; j < k; ++j) {
      if (i - lr[j].first < 1)
        continue;
      ll diff =
          (dp[i - lr[j].first] - dp[max(0, i - lr[j].second - 1)] + MOD) % MOD;
      dp[i] += diff;
      dp[i] %= MOD;
    }
  }

  cout << dp[n] << endl;
}


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

#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rep2(i, s, n) for (long long i = (s); i < (long long)(n); i++)
#define repi(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2i(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define chmax(s, t) s = max(s, t);
#define chmin(s, t) s = min(s, t);

#define deg2rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad2deg(rad) (((rad) / 2 / M_PI) * 360)

using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

const ll INF = (1LL << 60);
const int INFi = (1 << 29);

/*素数判定*/
bool is_prime(ll n) {
  if (n == 1)
    return false;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 0)
      return false;
  }
  return true;
}

/*約数列挙*/
vll enum_divisors(ll n) {
  vll l;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      l.push_back(i);
      if (n / i != i)
        l.push_back(n / i);
    }
  }
  sort(all(l));
  return l;
}

/*素因数分解*/
vector<P> prime_factorize(ll n) {
  vector<P> l;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i != 0)
      continue;
    ll e = 0;
    while (n % i == 0) {
      e++;
      n /= i;
    }
    l.push_back({i, e});
  }
  if (n != 1)
    l.push_back({n, 1});
  return l;
}

/*最小公倍数*/
ll lcm(ll a, ll b) { return a * b / __gcd(a, b); }

/*最大公約数*/
ll gcd(ll a, ll b) { return __gcd(a, b); }

/*組み合わせ(Combination)*/
const ll CMAX = 1010000;
const ll CMOD = 1e9 + 7;
ll fac[CMAX], finv[CMAX], inv[CMAX];
// テーブルを作る前処理
void combinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (ll i = 2; i < CMAX; i++) {
    fac[i] = fac[i - 1] * i % CMOD;
    inv[i] = CMOD - inv[CMOD % i] * (CMOD / i) % CMOD;
    finv[i] = finv[i - 1] * inv[i] % CMOD;
  }
}
// 二項係数計算
ll comb(ll n, ll k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % CMOD) % CMOD;
}

/*階乗*/
ll factorial(ll n) {
  const ll FMOD = 1e9 + 7;
  ll ret = n;
  for (ll i = n - 1; i > 0; i--) {
    ret *= i;
    ret %= FMOD;
  }
  return (ret ? ret : 1);
}

int main() {

  ll n, k;
  cin >> n >> k;
  set<ll> s;
  rep(i, k) {
    ll l, r;
    cin >> l >> r;
    rep2(j, l, r + 1) { s.insert(j); }
  }
  ll mod = 998244353;
  vll dp(n, 0);
  dp[0] = 1;
  rep2(i, 1, n) {
    for (ll x : s) {
      if (i - x >= 0) {
        dp[i] += (dp[i - x] % mod);
        dp[i] %= mod;
      }
    }
  }

  cout << dp[n - 1] << endl;

  return 0;
}

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

#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rep2(i, s, n) for (long long i = (s); i < (long long)(n); i++)
#define repi(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2i(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define chmax(s, t) s = max(s, t);
#define chmin(s, t) s = min(s, t);

#define deg2rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad2deg(rad) (((rad) / 2 / M_PI) * 360)

using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

const ll INF = (1LL << 60);
const int INFi = (1 << 29);

/*素数判定*/
bool is_prime(ll n) {
  if (n == 1)
    return false;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 0)
      return false;
  }
  return true;
}

/*約数列挙*/
vll enum_divisors(ll n) {
  vll l;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      l.push_back(i);
      if (n / i != i)
        l.push_back(n / i);
    }
  }
  sort(all(l));
  return l;
}

/*素因数分解*/
vector<P> prime_factorize(ll n) {
  vector<P> l;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i != 0)
      continue;
    ll e = 0;
    while (n % i == 0) {
      e++;
      n /= i;
    }
    l.push_back({i, e});
  }
  if (n != 1)
    l.push_back({n, 1});
  return l;
}

/*最小公倍数*/
ll lcm(ll a, ll b) { return a * b / __gcd(a, b); }

/*最大公約数*/
ll gcd(ll a, ll b) { return __gcd(a, b); }

/*組み合わせ(Combination)*/
const ll CMAX = 1010000;
const ll CMOD = 1e9 + 7;
ll fac[CMAX], finv[CMAX], inv[CMAX];
// テーブルを作る前処理
void combinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (ll i = 2; i < CMAX; i++) {
    fac[i] = fac[i - 1] * i % CMOD;
    inv[i] = CMOD - inv[CMOD % i] * (CMOD / i) % CMOD;
    finv[i] = finv[i - 1] * inv[i] % CMOD;
  }
}
// 二項係数計算
ll comb(ll n, ll k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % CMOD) % CMOD;
}

/*階乗*/
ll factorial(ll n) {
  const ll FMOD = 1e9 + 7;
  ll ret = n;
  for (ll i = n - 1; i > 0; i--) {
    ret *= i;
    ret %= FMOD;
  }
  return (ret ? ret : 1);
}

int main() {

  ll n, k;
  cin >> n >> k;
  vll l(k), r(k);
  rep(i, k) { cin >> l[i] >> r[i]; }

  ll mod = 998244353;
  vll dp(n + 1), sum(n + 1);
  dp[1] = 1;
  sum[1] = 1;
  rep2(i, 2, n + 1) {
    rep(j, k) {
      ll li = i - r[j];
      ll ri = i - l[j];
      if (ri < 0)
        continue;
      li = max(li, 1LL);
      dp[i] += sum[ri] - sum[li - 1];
      dp[i] %= mod;
    }
    sum[i] = sum[i - 1] + dp[i];
  }

  cout << dp[n] << endl;

  return 0;
}


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

const int mod = 998244353;
int A[200005];
int f[200005];

int main() {
  int N, K;
  scanf("%d%d", &N, &K);

  set<int> s;
  set<int>::iterator it;
  int flag = 1;
  for (int i = 1; i <= K; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    for (int j = x; j <= y; ++j)
      s.insert(j);
  }
  f[1] = 1;
  for (int i = 1; i <= N; ++i) {
    for (it = s.begin(); it != s.end(); ++it) {
      if (i + *it <= N)
        f[i + *it] = (f[i + *it] + f[i]) % mod;
      else
        break;
    }
  }
  cout << f[N];
  return 0;
}

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

const int mod = 998244353;
const int maxn = 200000 + 5;
ll f[maxn], a[maxn], b[maxn];
ll c[20];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);

  for (int i = 0; i < m; ++i)
    scanf("%d%d", &a[i], &b[i]);

  f[1] = 1;
  for (int i = 2; i <= n; ++i)
    for (int j = 0; j < m; ++j) {
      c[j] += (i - a[j] >= 1 ? f[i - a[j]] : 0) -
              (i - b[j] - 1 >= 1 ? f[i - b[j] - 1] : 0);
      f[i] = (f[i] + c[j]) % mod;
    }
  cout << f[n];
  return 0;
}


#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
const int INF = 1001001001;
const int mod = 998244353;
struct mint {
  // 自動的にmodを取ってくれるクラスです。
  ll x;
  mint(ll x = 0) : x(x % mod) {}
  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 b = pow(t / 2);
    b *= b;
    if (t % 2 == 1)
      b *= *this;
    return b;
  }

  mint inv() const { return pow(mod - 2); }
  mint &operator/=(const mint a) {
    (*this) *= a.inv();
    return *this;
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};

int main() {
  int n, k;
  cin >> n >> k;
  set<int> s;
  vector<mint> dp(n);
  rep(i, k) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++)
      s.insert(j);
  }
  // vector<int> sv;
  // for(auto itr = s.begin(); itr != s.end();itr++){
  //     int t = *itr;
  //     cout << t << endl;
  //     // sv.push_back(t);
  // }
  // sort(sv.begin(),sv.end());
  dp.at(0) = mint(1);
  rep(i, n) {
    for (auto itr = s.begin(); itr != s.end(); itr++) {
      int t = *itr;
      if ((i - t) < 0)
        continue;
      dp.at(i) += dp.at(i - t);
    }
  }
  cout << dp.at(n - 1).x << endl;
}

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
const int INF = 1001001001;
const int mod = 998244353;
struct mint {
  // 自動的にmodを取ってくれるクラスです。
  ll x;
  mint(ll x = 0) : x(x % mod) {}
  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 b = pow(t / 2);
    b *= b;
    if (t % 2 == 1)
      b *= *this;
    return b;
  }

  mint inv() const { return pow(mod - 2); }
  mint &operator/=(const mint a) {
    (*this) *= a.inv();
    return *this;
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};

int main() {
  int n, k;
  cin >> n >> k;
  vector<mint> dp(n + 1);
  vector<mint> dpsum(n + 1);
  vector<int> l(k), r(k);
  rep(i, k) cin >> l.at(i) >> r.at(i);
  dp.at(1) = mint(1);
  dpsum.at(1) = mint(1);
  for (int i = 2; i <= n; i++) {
    rep(j, k) {
      int li = i - r.at(j);
      int ri = i - l.at(j);
      if (ri < 0)
        continue;
      li = max(li, 1);
      dp.at(i) += dpsum.at(ri) - dpsum.at(li - 1);
    }
    dpsum.at(i) = dpsum.at(i - 1) + dp.at(i);
  }
  cout << dp.at(n).x << endl;
}


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

int main() {
  long long N;
  int K, scount;
  scount = 0;
  cin >> N >> K;
  vector<int> L(K);
  vector<int> R(K);
  vector<int> table(N + 2, 0);
  vector<int> S = {};
  for (int i = 0; i < K; i++) {
    cin >> L.at(i) >> R.at(i);
    table.at(L.at(i))++;
    table.at(R.at(i) + 1)--;
  }
  for (int i = 1; i <= N; i++) {
    table.at(i) += table.at(i - 1);
    // cout << table.at(i) << endl;
    if (table.at(i) == 1)
      S.emplace_back(i);
  }
  sort(table.begin(), table.end());

  vector<long long> dp(N + 1, 0);
  dp.at(1) = 1;
  for (int i = 2; i <= N; i++) {
    for (int j = 0; j < S.size(); j++) {
      if (i - S.at(j) >= 0)
        dp.at(i) += dp.at(i - S.at(j));
      else
        continue;
    }
  }

  cout << dp.at(N) % 998244353 << endl;
}

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

int main() {
  long long N;
  int K;
  cin >> N >> K;
  vector<int> L(K);
  vector<int> R(K);
  for (int i = 0; i < K; i++) {
    cin >> L[i] >> R[i];
  }
  vector<long long> dp(N + 1, 0);
  vector<long long> dpsum(N + 1, 0);
  dp[1] = 1;
  dpsum[1] = 1;

  for (int i = 2; i <= N; i++) {
    for (int j = 0; j < K; j++) {
      // if(i < R[j])continue;
      dp[i] += dpsum[max(i - L[j], 0)] - dpsum[max(i - R[j] - 1, 0)];
      dp[i] %= 998244353;
    }
    dpsum[i] = dpsum[i - 1] + dp[i];
    dpsum[i] %= 998244353;
    // cout << dp[i] << endl;
    // cout << dpsum[i] << endl;
  }

  if (dp[N] < 0)
    dp[N] += 998244353;
  cout << dp[N] << endl;
}


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

#define rep(i, a, b) for (int i = a; i <= b; i++)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)x.size()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int MOD = 998244353;

int n, k, l, r;
vector<pii> seg;
ll dp[200001];

ll calc(int x) {
  if (x > n)
    return 0;
  if (x == n)
    return 1;
  if (dp[x] != -1)
    return dp[x];

  ll ans = 0;
  bool bad = false;
  trav(s, seg) {
    rep(i, s.first, s.second) {
      if (x + i > n)
        break;
      ans = (ans + calc(x + i)) % MOD;
    }
    if (bad)
      break;
  }
  return dp[x] = ans % MOD;
}

int main() {
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
  cin.sync_with_stdio(0);
  cin.tie();
  cin.exceptions(cin.failbit);

  cin >> n >> k;
  rep(i, 1, k) {
    cin >> l >> r;
    seg.pb({l, r});
  }
  sort(all(seg));

  rep(i, 1, n) dp[i] = -1;
  cout << calc(1);
}

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

#define rep(i, a, b) for (int i = a; i <= b; i++)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)x.size()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int MOD = 998244353;

int n, k, l, r;
vector<pii> vec;
ll dp[200001];

struct segtree {
  int size;
  vector<ll> sums;

  void init(int n) {
    size = 1;
    while (size < n)
      size *= 2;
    sums.assign(2 * size, 0LL);
  }

  void build(vector<ll> &a, int x, int lx, int rx) {
    if (rx - lx == 1) {
      if (lx < (int)a.size())
        sums[x] = a[lx];
      return;
    }
    int m = (lx + rx) / 2;
    build(a, 2 * x + 1, lx, m);
    build(a, 2 * x + 2, m, rx);
    sums[x] = sums[2 * x + 1] + sums[2 * x + 2];
  }

  void build(vector<ll> &a) { build(a, 0, 0, size); }

  void set(int i, int v, int x, int lx, int rx) {
    if (rx - lx == 1) {
      sums[x] = v;
      return;
    }
    int m = (lx + rx) / 2;
    if (i < m) {
      set(i, v, 2 * x + 1, lx, m);
    } else {
      set(i, v, 2 * x + 2, m, rx);
    }
    sums[x] = sums[2 * x + 1] + sums[2 * x + 2];
  }

  void set(int i, int v) { set(i, v, 0, 0, size); }

  ll sum(int l, int r, int x, int lx, int rx) {
    if (lx >= l && rx <= r)
      return sums[x];
    if (lx >= r || rx <= l)
      return 0;
    int m = (lx + rx) / 2;
    ll s1 = sum(l, r, 2 * x + 1, lx, m);
    ll s2 = sum(l, r, 2 * x + 2, m, rx);
    return s1 + s2;
  }

  ll sum(int l, int r) { return sum(l, r, 0, 0, size); }
};

int main() {
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
  cin.sync_with_stdio(0);
  cin.tie();
  cin.exceptions(cin.failbit);

  ll n, k, l, r;
  cin >> n >> k;
  vector<ll> dp(n + 1);
  dp[n] = 1;
  segtree st;
  st.init(n + 1);
  st.build(dp);

  rep(i, 1, k) {
    cin >> l >> r;
    vec.pb({l, r});
  }

  for (int i = n - 1; i >= 1; i--) {
    ll ans = 0;
    trav(s, vec) {
      if (i + s.first <= n) {
        ans = (ans +
               st.sum(i + s.first, min(n + 1, (ll)i + s.second + 1)) % MOD) %
              MOD;
      }
    }
    ans %= MOD;
    dp[i] = ans;
    st.set(i, ans);
  }

  cout << dp[1];
}


#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl '\\n'
// #define int long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define BIT(n) (1LL << (n))
#define TOUPPER(s) transform(s.begin(), s.end(), s.begin(), ::toupper)
#define TOLOWER(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
#define FILLZERO(s, n)                                                         \\
  do {                                                                         \\
    ostringstream os;                                                          \\
    os << setw(n) << setfill('0') << s;                                        \\
    s = os.str();                                                              \\
  } while (0);
#define UNIQUE(v)                                                              \\
  v.erase(unique(v.begin(), v.end()), v.end()) // sortしてからつかうこと
#define INIT                                                                   \\
  std::cin.tie(nullptr);                                                       \\
  std::ios_base::sync_with_stdio(false);                                       \\
  cout << std::fixed << std::setprecision(10);

using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using pi = pair<int, int>;
template <typename T> using Pq = priority_queue<T>;
template <typename T> using pQ = priority_queue<T, vector<T>, greater<T>>;

template <typename T> vector<T> make_vec(size_t a, T n) {
  return vector<T>(a, n);
}
template <typename T, typename... Ts> auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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 <typename T> istream &operator>>(istream &is, vector<T> &vec) {
  for (T &x : vec)
    is >> x;
  return is;
}

constexpr ll MOD = 998244353;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

class Fp {
private:
  long long val;

public:
  static long long mod;

  Fp() { val = 0; }
  Fp(long long v) : val(v % mod) {
    if (val < 0)
      val += mod;
  }
  Fp getVal() { return val; }
  Fp operator+=(const Fp &in) {
    val += in.val;
    if (val >= mod)
      val -= mod;
    return *this;
  }
  Fp operator+(const Fp &in) const { return Fp(*this) += in; }
  Fp &operator-=(const Fp &in) {
    val -= in.val;
    if (val < 0)
      val += mod;
    return *this;
  }
  Fp operator-(const Fp &in) const { return Fp(*this) -= in; }
  Fp &operator*=(const Fp &in) {
    val = val * in.val % mod;
    return *this;
  }
  Fp operator*(const Fp &in) const { return Fp(*this) *= in; }
  friend Fp operator*(const long long n, const Fp &in) { return in * n; }
  Fp &operator/=(const Fp &in) {
    *this *= in.modpow(mod - 2);
    return *this;
  }
  Fp operator/(const Fp &in) const { return Fp(*this) /= in; }
  bool operator==(const Fp &in) const { return val == in.val; }
  bool operator!=(const Fp &in) const { return val != in.val; }
  Fp modpow(long long n) const {
    if (n == 0)
      return 1;
    if (n & 1) {
      return (*this) * ((*this) * (*this)).modpow(n / 2);
    } else {
      return ((*this) * (*this)).modpow(n / 2);
    }
  }
  friend istream &operator>>(istream &is, Fp &fp) {
    is >> fp.val;
    return is;
  }
  friend ostream &operator<<(ostream &os, Fp &fp) {
    os << fp.val;
    return os;
  }
  friend ostream &operator<<(ostream &os, Fp &&fp) {
    os << fp.val;
    return os;
  }
};

Fp modpow(const Fp &in, const long long n) { return in.modpow(n); }
Fp modpow(const ll a, const long long n) { return Fp(a).modpow(n); }

using mint = Fp;
long long mint::mod = MOD;

class Factorial {
public:
  vector<mint> fact, finv;
  Factorial(long long n) : fact(n + 1, mint(1)), finv(n + 1, mint(1)) {
    for (int i = 2; i <= n; i++) {
      mint tmp(i);
      fact[i] = fact[i - 1] * tmp;
      finv[i] = finv[i - 1] / tmp;
    }
  }
  mint perm(const long long n, const long long k) {
    return fact[n] * finv[n - k];
  }
  mint com(const long long n, const long long k) {
    if (n < k || n < 0 || k < 0)
      return mint(0);
    return fact[n] * finv[k] * finv[n - k];
  }
};

template <typename T> class segment_tree {
public:
  segment_tree(int n_)
      : n(__lowest_power_of_2(n_)), dat(n * 2, 0), lazy(n * 2, 0) {}

  template <typename Iterator>
  segment_tree(Iterator left, Iterator right)
      : n(__lowest_power_of_2(std::distance(left, right))), dat(n * 2, 0),
        lazy(n * 2, 0) {
    std::copy(left + n, right + n, dat.begin());
    for (int i = n - 1; i >= 1; --i) {
      dat[i] = std::max(dat[i * 2], dat[i * 2 + 1]);
    }
  }

private:
  int n;
  std::vector<T> dat, lazy;

public:
  void add(int ql, int qr, const T &x) { __add(1, 0, n, ql, qr, x); }

  T sum(int ql, int qr) { return __sum(1, 0, n, ql, qr); }

private:
  void __flush_lazy(int v, int l, int r) {
    dat[v] += lazy[v] * (r - l);
    if (v < n) {
      lazy[v * 2] += lazy[v];
      lazy[v * 2 + 1] += lazy[v];
    }
    lazy[v] = 0;
  }

  void __update_dat(int v) { dat[v] = dat[v * 2] + dat[v * 2 + 1]; }

  void __add(int n, int l, int r, const int ql, const int qr, const T &x) {
    __flush_lazy(n, l, r);
    if (r <= ql || qr <= l) {
      return;
    } else if (ql <= l && r <= qr) {
      lazy[n] += x;
      __flush_lazy(n, l, r);
    } else {
      int m = (l + r) / 2;
      __add(n * 2, l, m, ql, qr, x);
      __add(n * 2 + 1, m, r, ql, qr, x);
      __update_dat(n);
    }
  }

  T __sum(int n, int l, int r, const int ql, const int qr) {
    __flush_lazy(n, l, r);
    if (r <= ql || qr <= l) {
      return 0;
    } else if (ql <= l && r <= qr) {
      return dat[n];
    } else {
      int m = (l + r) / 2;
      T res_left = __sum(n * 2, l, m, ql, qr);
      T res_right = __sum(n * 2 + 1, m, r, ql, qr);
      __update_dat(n);
      return res_left + res_right;
    }
  }

  int __lowest_power_of_2(int x) const {
    int res = 1;
    while (res < x)
      res <<= 1;
    return res;
  }
};

signed main() {
  INIT;
  cin >> N >> K;
  vector<pi> lr(K);
  REP(i, K) { cin >> lr[i].first >> lr[i].second; }
  segment_tree<mint> st(N);
  dump("hoge");
  st.add(0, 1, 1);
  REP(i, N) {
    auto now = st.sum(i, i + 1);
    REP(j, K) {
      st.add(i + lr[j].first, min(i + lr[j].second + 1, int(N)), now);
    }
  }
  cout << st.sum(N - 1, N) << endl;
}

#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl '\\n'
// #define int long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define BIT(n) (1LL << (n))
#define TOUPPER(s) transform(s.begin(), s.end(), s.begin(), ::toupper)
#define TOLOWER(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
#define FILLZERO(s, n)                                                         \\
  do {                                                                         \\
    ostringstream os;                                                          \\
    os << setw(n) << setfill('0') << s;                                        \\
    s = os.str();                                                              \\
  } while (0);
#define UNIQUE(v)                                                              \\
  v.erase(unique(v.begin(), v.end()), v.end()) // sortしてからつかうこと
#define INIT                                                                   \\
  std::cin.tie(nullptr);                                                       \\
  std::ios_base::sync_with_stdio(false);                                       \\
  cout << std::fixed << std::setprecision(10);

using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using pi = pair<int, int>;
template <typename T> using Pq = priority_queue<T>;
template <typename T> using pQ = priority_queue<T, vector<T>, greater<T>>;

template <typename T> vector<T> make_vec(size_t a, T n) {
  return vector<T>(a, n);
}
template <typename T, typename... Ts> auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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 <typename T> istream &operator>>(istream &is, vector<T> &vec) {
  for (T &x : vec)
    is >> x;
  return is;
}

constexpr ll mod = 998244353;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

class Fp {
private:
  long long val;

public:
  Fp() { val = 0; }
  Fp(long long v) : val(v % mod) {
    if (val < 0)
      val += mod;
  }
  Fp getVal() { return val; }
  Fp operator+=(const Fp &in) {
    val += in.val;
    if (val >= mod)
      val -= mod;
    return *this;
  }
  Fp operator+(const Fp &in) const { return Fp(*this) += in; }
  Fp &operator-=(const Fp &in) {
    val -= in.val;
    if (val < 0)
      val += mod;
    return *this;
  }
  Fp operator-(const Fp &in) const { return Fp(*this) -= in; }
  Fp &operator*=(const Fp &in) {
    val = val * in.val % mod;
    return *this;
  }
  Fp operator*(const Fp &in) const { return Fp(*this) *= in; }
  friend Fp operator*(const long long n, const Fp &in) { return in * n; }
  Fp &operator/=(const Fp &in) {
    *this *= in.modpow(mod - 2);
    return *this;
  }
  Fp operator/(const Fp &in) const { return Fp(*this) /= in; }
  bool operator==(const Fp &in) const { return val == in.val; }
  bool operator!=(const Fp &in) const { return val != in.val; }
  Fp modpow(long long n) const {
    if (n == 0)
      return 1;
    if (n & 1) {
      return (*this) * ((*this) * (*this)).modpow(n / 2);
    } else {
      return ((*this) * (*this)).modpow(n / 2);
    }
  }
  friend istream &operator>>(istream &is, Fp &fp) {
    is >> fp.val;
    return is;
  }
  friend ostream &operator<<(ostream &os, Fp &fp) {
    os << fp.val;
    return os;
  }
  friend ostream &operator<<(ostream &os, Fp &&fp) {
    os << fp.val;
    return os;
  }
};

Fp modpow(const Fp &in, const long long n) { return in.modpow(n); }
Fp modpow(const ll a, const long long n) { return Fp(a).modpow(n); }

using mint = Fp;

class Factorial {
public:
  vector<mint> fact, finv;
  Factorial(long long n) : fact(n + 1, mint(1)), finv(n + 1, mint(1)) {
    for (int i = 2; i <= n; i++) {
      mint tmp(i);
      fact[i] = fact[i - 1] * tmp;
      finv[i] = finv[i - 1] / tmp;
    }
  }
  mint perm(const long long n, const long long k) {
    return fact[n] * finv[n - k];
  }
  mint com(const long long n, const long long k) {
    if (n < k || n < 0 || k < 0)
      return mint(0);
    return fact[n] * finv[k] * finv[n - k];
  }
};

template <typename T> class segment_tree {
public:
  segment_tree(int n_)
      : n(__lowest_power_of_2(n_)), dat(n * 2, 0), lazy(n * 2, 0) {}

  template <typename Iterator>
  segment_tree(Iterator left, Iterator right)
      : n(__lowest_power_of_2(std::distance(left, right))), dat(n * 2, 0),
        lazy(n * 2, 0) {
    std::copy(left + n, right + n, dat.begin());
    for (int i = n - 1; i >= 1; --i) {
      dat[i] = std::max(dat[i * 2], dat[i * 2 + 1]);
    }
  }

private:
  int n;
  std::vector<T> dat, lazy;

public:
  void add(int ql, int qr, const T &x) { __add(1, 0, n, ql, qr, x); }

  T sum(int ql, int qr) { return __sum(1, 0, n, ql, qr); }

private:
  void __flush_lazy(int v, int l, int r) {
    dat[v] += lazy[v] * (r - l);
    if (v < n) {
      lazy[v * 2] += lazy[v];
      lazy[v * 2 + 1] += lazy[v];
    }
    lazy[v] = 0;
  }

  void __update_dat(int v) { dat[v] = dat[v * 2] + dat[v * 2 + 1]; }

  void __add(int n, int l, int r, const int ql, const int qr, const T &x) {
    __flush_lazy(n, l, r);
    if (r <= ql || qr <= l) {
      return;
    } else if (ql <= l && r <= qr) {
      lazy[n] += x;
      __flush_lazy(n, l, r);
    } else {
      int m = (l + r) / 2;
      __add(n * 2, l, m, ql, qr, x);
      __add(n * 2 + 1, m, r, ql, qr, x);
      __update_dat(n);
    }
  }

  T __sum(int n, int l, int r, const int ql, const int qr) {
    __flush_lazy(n, l, r);
    if (r <= ql || qr <= l) {
      return 0;
    } else if (ql <= l && r <= qr) {
      return dat[n];
    } else {
      int m = (l + r) / 2;
      T res_left = __sum(n * 2, l, m, ql, qr);
      T res_right = __sum(n * 2 + 1, m, r, ql, qr);
      __update_dat(n);
      return res_left + res_right;
    }
  }

  int __lowest_power_of_2(int x) const {
    int res = 1;
    while (res < x)
      res <<= 1;
    return res;
  }
};

signed main() {
  INIT;
  cin >> N >> K;
  vector<pi> lr(K);
  REP(i, K) { cin >> lr[i].first >> lr[i].second; }
  segment_tree<mint> st(N);
  dump("hoge");
  st.add(0, 1, 1);
  REP(i, N) {
    auto now = st.sum(i, i + 1);
    REP(j, K) {
      st.add(i + lr[j].first, min(i + lr[j].second + 1, int(N)), now);
    }
  }
  cout << st.sum(N - 1, N) << endl;
}


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

int main() {
  const int64_t mod = 998244353;
  int N, K;
  cin >> N >> K;
  set<int> s;
  int L, R;
  for (int i = 0; i < K; i++) {
    cin >> L >> R;
    for (int j = L; j <= R; j++) {
      s.insert(j);
    }
  }
  vector<int64_t> dp(N + 1, 0);
  dp.at(1) = 1;
  for (int i = 2; i <= N; i++) {
    for (auto x : s) {
      if (i > x) {
        dp.at(i) += dp.at(i - x);
        dp.at(i) %= mod;
      } else {
        break;
      }
    }
  }
  cout << dp.at(N) << endl;
  return 0;
}

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

int main() {
  const int64_t mod = 998244353;
  int N, K;
  cin >> N >> K;
  vector<pair<int, int>> vp(K);
  for (int i = 0; i < K; i++) {
    cin >> vp.at(i).first >> vp.at(i).second;
  }
  vector<int64_t> dp(N + 1, 0), sum(N + 1, 0);
  dp.at(1) = 1;
  sum.at(1) = sum.at(0) + dp.at(1);
  for (int i = 2; i <= N; i++) {
    for (int j = 0; j < K; j++) {
      if (i > vp.at(j).first) {
        dp.at(i) += (sum.at(i - vp.at(j).first) -
                     sum.at(max(0, i - vp.at(j).second - 1))) %
                    mod;
        dp.at(i) %= mod;
      }
    }
    sum.at(i) += (sum.at(i - 1) + dp.at(i)) % mod;
    sum.at(i) %= mod;
  }
  if (dp.at(N) < 0) {
    dp.at(N) += mod;
  }
  cout << dp.at(N) << endl;
  return 0;
}


#include <bits/stdc++.h>
#define MOD 998244353
typedef long long ll;
using namespace std;
struct mint {
  ll x;
  mint(ll x = 0) : x((x % MOD + MOD) % MOD) {}
  mint operator-() { return mint(-x); }
  mint operator+=(mint rhs) {
    x += rhs.x;
    if (x >= MOD)
      x -= MOD;
    return *this;
  }
  mint operator-=(mint rhs) {
    x -= rhs.x;
    if (x < 0)
      x += MOD;
    return *this;
  }
  mint operator*=(mint rhs) {
    x = x * rhs.x % MOD;
    return *this;
  }
  mint operator+(mint rhs) { return mint(*this) += rhs; }
  mint operator-(mint rhs) { return mint(*this) -= rhs; }
  mint operator*(mint rhs) { return mint(*this) *= rhs; }
};
// ostream &operator<<(ostream &os, const mint &dt) {
// 	os << dt.x;
// 	return os;
// }
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> l(k), r(k);
  for (int i = 0; i < k; i++) {
    cin >> l[i] >> r[i];
  }
  vector<mint> dp(n + 10, 0);
  vector<mint> sum(n + 10, 0);
  dp[0] = 1;
  mint p = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < k; j++) {
      // if (i + l[j] > n + 1) continue;
      sum[i + l[j]] += dp[i];
      sum[i + r[j] + 1] -= dp[i];
    }
    p += sum[i + 1];
    dp[i + 1] = p;
    // cout << "p:" << p << endl;
    // cout << "sum:";
    // for (int ii = 0; ii <= n; ii++) {
    // 	cout << sum[ii];
    // 	if (ii == n)
    // 		cout << endl;
    // 	else
    // 		cout << " ";
    // }
    // cout << "dp:";
    // for (int ii = 0; ii <= n; ii++) {
    // 	cout << dp[ii];
    // 	if (ii == n)
    // 		cout << endl;
    // 	else
    // 		cout << " ";
    // }
  }
  // for (int i = 0; i <= n; i++) {
  // 	cout << dp[i];
  // 	if (i == n)
  // 		cout << endl;
  // 	else
  // 		cout << " ";
  // }
  cout << dp[n - 1].x << endl;
  return 0;
}

#include <bits/stdc++.h>
#define MOD 998244353
typedef long long ll;
using namespace std;
struct mint {
  ll x;
  mint(ll x = 0) : x((x % MOD + MOD) % MOD) {}
  mint operator-() { return mint(-x); }
  mint operator+=(mint rhs) {
    x += rhs.x;
    if (x >= MOD)
      x -= MOD;
    return *this;
  }
  mint operator-=(mint rhs) {
    x -= rhs.x;
    if (x < 0)
      x += MOD;
    return *this;
  }
  mint operator*=(mint rhs) {
    x = x * rhs.x % MOD;
    return *this;
  }
  mint operator+(mint rhs) { return mint(*this) += rhs; }
  mint operator-(mint rhs) { return mint(*this) -= rhs; }
  mint operator*(mint rhs) { return mint(*this) *= rhs; }
};
// ostream &operator<<(ostream &os, const mint &dt) {
// 	os << dt.x;
// 	return os;
// }
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> l(k), r(k);
  for (int i = 0; i < k; i++) {
    cin >> l[i] >> r[i];
  }
  vector<mint> dp(n + 10, 0);
  vector<mint> sum(n + 10, 0);
  dp[0] = 1;
  mint p = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < k; j++) {
      if (i + l[j] <= n + 1)
        sum[i + l[j]] += dp[i];
      if (i + r[j] + 1 <= n + 1)
        sum[i + r[j] + 1] -= dp[i];
    }
    p += sum[i + 1];
    dp[i + 1] = p;
    // cout << "p:" << p << endl;
    // cout << "sum:";
    // for (int ii = 0; ii <= n; ii++) {
    // 	cout << sum[ii];
    // 	if (ii == n)
    // 		cout << endl;
    // 	else
    // 		cout << " ";
    // }
    // cout << "dp:";
    // for (int ii = 0; ii <= n; ii++) {
    // 	cout << dp[ii];
    // 	if (ii == n)
    // 		cout << endl;
    // 	else
    // 		cout << " ";
    // }
  }
  // for (int i = 0; i <= n; i++) {
  // 	cout << dp[i];
  // 	if (i == n)
  // 		cout << endl;
  // 	else
  // 		cout << " ";
  // }
  cout << dp[n - 1].x << endl;
  return 0;
}


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

#define IO                                                                     \\
  ios_base ::sync_with_stdio(0);                                               \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define int long long
#define double long double
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define vii vector<pii>
#define nl '\\n'
#define yy "YES\\n"
#define nn "NO\\n"
#define pb emplace_back
#define mkpr make_pair
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define mod 998244353

struct BIT {
  vector<int> bit; // binary indexed tree
  int n;

  BIT(int n) {
    this->n = n + 1;
    bit.assign(n + 1, 0);
  }

  int sum(int idx) {
    int ret = 0;
    if (idx <= 0) {
      return 0;
    }
    for (++idx; idx > 0; idx -= idx & -idx)
      ret += bit[idx], ret %= mod;
    return ret;
  }

  int sum(int l, int r) {
    int x = sum(r);
    int y = sum(l - 1);
    int ans = (x - y + mod) % mod;
    return ans;
  }

  void add(int idx, int delta) {
    for (++idx; idx < n; idx += idx & -idx)
      bit[idx] += delta;
    bit[idx] %= mod;
  }
};

signed main() {
  IO;
  int n, k;
  cin >> n >> k;
  BIT b(n);
  vi dp(n + 1);
  vii segs(k);
  for (int i = 0; i < k; i++) {
    cin >> segs[i].first >> segs[i].second;
  }
  sort(all(segs));
  b.add(1, 1);
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < k; j++) {
      int l = segs[j].first, r = segs[j].second;
      int needl = max(0LL, i - r), needr = max(0LL, i - l);
      dp[i] += b.sum(needl, needr);
      dp[i] %= mod;
    }
    b.add(i, dp[i]);
  }
  cout << dp[n];
}

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

#define IO                                                                     \\
  ios_base ::sync_with_stdio(0);                                               \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define int long long
#define double long double
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define vii vector<pii>
#define nl '\\n'
#define yy "YES\\n"
#define nn "NO\\n"
#define pb emplace_back
#define mkpr make_pair
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define mod 998244353

struct BIT {
  vector<int> bit; // binary indexed tree
  int n;

  BIT(int n) {
    this->n = n + 1;
    bit.assign(n + 1, 0);
  }

  int sum(int idx) {
    int ret = 0;
    if (idx <= 0) {
      return 0;
    }
    for (++idx; idx > 0; idx -= idx & -idx)
      ret += bit[idx], ret %= mod;
    return ret;
  }

  int sum(int l, int r) {
    int x = sum(r);
    int y = sum(l - 1);
    int ans = (x - y + mod) % mod;
    return ans;
  }

  void add(int idx, int delta) {
    for (++idx; idx < n; idx += idx & -idx) {
      bit[idx] += delta;
      bit[idx] %= mod;
    }
  }
};

signed main() {
  IO;
  int n, k;
  cin >> n >> k;
  BIT b(n);
  vi dp(n + 1);
  vii segs(k);
  for (int i = 0; i < k; i++) {
    cin >> segs[i].first >> segs[i].second;
  }
  sort(all(segs));
  b.add(1, 1);
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < k; j++) {
      int l = segs[j].first, r = segs[j].second;
      int needl = max(0LL, i - r), needr = max(0LL, i - l);
      dp[i] += b.sum(needl, needr);
      dp[i] %= mod;
    }
    b.add(i, dp[i]);
  }
  cout << dp[n];
}


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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> l(k + 1), r(k + 1);
  for (int i = 1; i <= k; i++) {
    cin >> l[i] >> r[i];
  }

  vector<ll> dp(n + 1);
  vector<ll> dpsum(n + 1);
  dp[1] = 1;
  dpsum[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 1; j <= k; j++) {
      int lim_r = i - l[j];
      int lim_l = i - r[j];
      dp[i] = (dp[i] + dpsum[lim_r] - dpsum[lim_l - 1]) % MOD;
    }
    dpsum[i] = (dp[i] + dp[i - 1]) % MOD;
  }
  cout << dp[n] << endl;
  return 0;
}

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> l(k + 1), r(k + 1);
  for (int i = 1; i <= k; i++) {
    cin >> l[i] >> r[i];
  }

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


/*
  Task: I. Kevin and Grid
  Link: http://codeforces.com/contest/1392/problem/I
  Lang: cpp17
*/
#include <bits/stdc++.h>
using namespace std;

#define eb emplace_back
#define pb push_back
#define INF LLONG_MAX
#define FLT_INF pow(10.0, 16)

using ll = long long;
using vll = vector<ll>;
using ull = unsigned long long;
using int2 = pair<ll, ll>;
using int3 = tuple<ll, ll, ll>;

template <typename A> string to_string(const A &v);
string to_string(const string &s) { return '"' + s + '"'; }
string to_string(const char *s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }

template <typename A, typename B> string to_string(const pair<A, B> &p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(const tuple<A, B, C> &p) {
  return "(" + to_string(std::get<0>(p)) + ", " + to_string(std::get<1>(p)) +
         ", " + to_string(std::get<2>(p)) + ")";
}

template <typename A> string to_string(const A &v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename T> void sort(vector<T> &val) {
  sort(val.begin(), val.end());
}

template <typename T> void reverse(vector<T> &val) {
  reverse(val.begin(), val.end());
}

template <typename T> void sort_b(vector<T> &val) {
  sort(val.begin(), val.end(), greater<T>());
}

template <typename T> T pair_sum(pair<T, T> &val) {
  return val.first + val.second;
}

template <typename T> T min(T a, T b, T c) { return min(min(a, b), c); }

template <typename T> T max(T a, T b, T c) { return max(max(a, b), c); }

template <typename T> T mul_mod(T a, T b, T mod) {
  T res = 0;
  a %= mod;
  while (b) {
    if (b & 1) {
      res = (res + a) % mod;
    }
    a = (2 * a) % mod;
    b >>= 1;
  }
  return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) ;
#endif

#define COMMON_MOD pow(10, 9) + 7
#define PI 3.14159265

// sort(a.begin(), a.end(), less<ll>()); greater<ll>()
// cout<<fixed<<setprecision(20)<<(s/kl)*2;
/* printf("%lld %lld \\n", cur_n, m / 2 + 1);
sort(a.begin(), a.end(), [ ](ll& lhs, ll& rhs) {return abs(lhs) < abs(rhs);});
*/

struct vertex {
  vll childs;
  bool seen;
};

const vertex ZERO_VERTEX = {};

class tree {
public:
  vector<vertex> verteces;

  tree(ll i) { verteces.assign(i, ZERO_VERTEX); }
};

struct node {
  ll first;
  ll second;
  ll color;
  bool operator<(const node &a) const { return first < a.first; }

  bool operator>(const node &a) const { return first > a.first; }
};

string to_string(node a) {
  return "{" + to_string(a.first) + ", " + to_string(a.second) + ", " +
         to_string(a.color) + "}";
}

class mytask {
public:
  mytask() {}

  int solve() {
    ll n, k;
    cin >> n >> k;
    set<ll> steps;
    for (ll i = 0; i < k; i++) {
      ll l, r;
      cin >> l >> r;
      for (ll j = l; j <= r; j++) {
        steps.insert(j);
      }
    }
    debug(steps);
    vll a(n + 1);
    a[1] = 1;
    for (ll i = 2; i <= n; i++) {
      debug(i);
      for (ll v : steps) {
        if (v < i) {
          a[i] += a[i - v];
          a[i] = a[i] % 998244353;
        }
      }
    }
    debug(a);
    cout << a[n];
    return 0;
  }
};

int main() {

  ios::sync_with_stdio(false);
  cin.tie(0);

  auto task = mytask();
  task.solve();

  // cout << endl;

  return 0;
}

/*
  Task: I. Kevin and Grid
  Link: http://codeforces.com/contest/1392/problem/I
  Lang: cpp17
*/
#include <bits/stdc++.h>
using namespace std;

#define eb emplace_back
#define pb push_back
#define INF LLONG_MAX
#define FLT_INF pow(10.0, 16)

using ll = long long;
using vll = vector<ll>;
using ull = unsigned long long;
using int2 = pair<ll, ll>;
using int3 = tuple<ll, ll, ll>;

template <typename A> string to_string(const A &v);
string to_string(const string &s) { return '"' + s + '"'; }
string to_string(const char *s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }

template <typename A, typename B> string to_string(const pair<A, B> &p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(const tuple<A, B, C> &p) {
  return "(" + to_string(std::get<0>(p)) + ", " + to_string(std::get<1>(p)) +
         ", " + to_string(std::get<2>(p)) + ")";
}

template <typename A> string to_string(const A &v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename T> void sort(vector<T> &val) {
  sort(val.begin(), val.end());
}

template <typename T> void reverse(vector<T> &val) {
  reverse(val.begin(), val.end());
}

template <typename T> void sort_b(vector<T> &val) {
  sort(val.begin(), val.end(), greater<T>());
}

template <typename T> T pair_sum(pair<T, T> &val) {
  return val.first + val.second;
}

template <typename T> T min(T a, T b, T c) { return min(min(a, b), c); }

template <typename T> T max(T a, T b, T c) { return max(max(a, b), c); }

template <typename T> T mul_mod(T a, T b, T mod) {
  T res = 0;
  a %= mod;
  while (b) {
    if (b & 1) {
      res = (res + a) % mod;
    }
    a = (2 * a) % mod;
    b >>= 1;
  }
  return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) ;
#endif

#define COMMON_MOD pow(10, 9) + 7
#define PI 3.14159265

// sort(a.begin(), a.end(), less<ll>()); greater<ll>()
// cout<<fixed<<setprecision(20)<<(s/kl)*2;
/* printf("%lld %lld \\n", cur_n, m / 2 + 1);
sort(a.begin(), a.end(), [ ](ll& lhs, ll& rhs) {return abs(lhs) < abs(rhs);});
*/

struct vertex {
  vll childs;
  bool seen;
};

const vertex ZERO_VERTEX = {};

class tree {
public:
  vector<vertex> verteces;

  tree(ll i) { verteces.assign(i, ZERO_VERTEX); }
};

struct node {
  ll first;
  ll second;
  ll color;
  bool operator<(const node &a) const { return first < a.first; }

  bool operator>(const node &a) const { return first > a.first; }
};

string to_string(node a) {
  return "{" + to_string(a.first) + ", " + to_string(a.second) + ", " +
         to_string(a.color) + "}";
}

class mytask {
public:
  mytask() {}

  int solve() {
    ll n, k;
    cin >> n >> k;
    // set<ll> steps;
    vector<int2> intervals;
    for (ll i = 0; i < k; i++) {
      ll l, r;
      cin >> l >> r;
      intervals.pb({l, r});
    }

    vll intervals_sums(k);
    vll a(n + 1);
    a[1] = 1;
    for (ll i = 2; i <= n; i++) {

      for (ll j = 0; j < k; j++) {
        auto [l, r] = intervals[j];
        if (i >= l)
          intervals_sums[j] += a[i - l];
        if (i > r)
          intervals_sums[j] -= a[i - r - 1];

        a[i] += intervals_sums[j];
        a[i] = a[i] % 998244353;
      }
    }
    debug(a);
    cout << a[n];
    return 0;
  }
};

int main() {

  ios::sync_with_stdio(false);
  cin.tie(0);

  auto task = mytask();
  task.solve();

  // cout << endl;

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define REP(i, x, n) for (int i = (x); i < (n); ++i)
#define ll long long
#define P pair<ll, ll>
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()

// const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1);
const ll mod = 998244353;

vector<ll> dp(220000);

int main(void) {
  ll n, k;
  cin >> n >> k;
  vector<P> a(k);
  rep(i, k) {
    ll l, r;
    cin >> l >> r;
    r++;
    a[i] = {l, r};
  }
  dp[1] = 1;
  dp[2] = -1;
  REP(i, 1, n + 1) {
    dp[i] += dp[i - 1];
    rep(j, k) {
      ll l, r;
      l = a[j].first;
      r = a[j].second;
      dp[i + l] += dp[i];
      dp[i + l] %= mod;
      dp[i + r] -= dp[i];
      dp[i + r] = (dp[i + r] + mod) % mod;
    }
  }
  cout << (dp[n] % mod + mod) % mod << endl;
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define REP(i, x, n) for (int i = (x); i < (n); ++i)
#define ll long long
#define P pair<ll, ll>
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()

// const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1);
const ll mod = 998244353;

vector<ll> dp(440000);

int main(void) {
  ll n, k;
  cin >> n >> k;
  vector<P> a(k);
  rep(i, k) {
    ll l, r;
    cin >> l >> r;
    r++;
    a[i] = {l, r};
  }
  dp[1] = 1;
  dp[2] = -1;
  REP(i, 1, n + 1) {
    dp[i] += dp[i - 1];
    rep(j, k) {
      ll l, r;
      l = a[j].first;
      r = a[j].second;
      dp[i + l] += dp[i];
      dp[i + l] %= mod;
      dp[i + r] -= dp[i];
      dp[i + r] = (dp[i + r] + mod) % mod;
    }
  }
  cout << (dp[n] % mod + mod) % mod << endl;
  return 0;
}


#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int P = 998244353;

  int N, K;
  vector<int> s;
  cin >> N >> K;

  for (int i = 0; i < K; ++i) {
    int l, r;
    cin >> l >> r;

    for (int j = l; j <= r; ++j) {
      s.push_back(j);
    }
  }

  sort(s.begin(), s.end());

  vector<int> c(N + 1, 0); // c[i]  1 から i ますまでのパスの数

  for (size_t j = 0; j < s.size(); ++j) {
    if (s[j] + 1 <= N) {
      c[s[j] + 1] = 1;
    }
  }

  for (int i = 1; i <= N; ++i) {
    for (size_t j = 0; j < s.size(); ++j) {
      if ((i - s[j]) >= 0) {
        c[i] = (c[i] + c[i - s[j]]) % P;
      } else {
        break;
      }
    }
  }

  cout << c[N] << endl;

  return 0;
}

#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>

using namespace std;

int main() {
  int P = 998244353;

  int N, K;
  //    vector<int> s;
  vector<pair<int, int>> s;
  cin >> N >> K;

  for (int i = 0; i < K; ++i) {
    int l, r;
    cin >> l >> r;

    s.push_back(pair<int, int>(l, r));
  }

  vector<int> c(N + 1, 0); // c[i]  1 から i ますまでのパスの数

  for (size_t j = 0; j < s.size(); ++j) {
    for (int k = 0; k < K; ++k) {
      for (int ss = s[k].first; ss <= s[k].second; ++ss) {
        if (ss + 1 <= N) {
          c[ss + 1] = 1;
        } else {
          break;
        }
      }
    }
  }

  vector<int> C(N + 1, 0); // C[i] = c[0] + .. + c[i];

  for (int i = 1; i <= N; ++i) {
    for (int k = 0; k < K; ++k) {
      // c[i - s[k].first] + .. + c[i - s[k].second] を加算

      int add; //  = C[s[k].second] - C[s[k].first - 1];
      int upper = max(i - s[k].first, 0);
      int lower = max(i - s[k].second - 1, 0);
      if (C[upper] >= C[lower]) {
        add = (C[upper] - C[lower]) % P;
      } else {
        add = (P + C[upper] - C[lower]) % P;
      }

      c[i] = (c[i] + add) % P;
    }

    C[i] = (C[i - 1] + c[i]) % P;
  }

  cout << c[N] << endl;

  return 0;
}


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

#define MOD (998244353)
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
#define nl '\\n'
#define all(x) x.begin(), x.end()
#define print(vec, l, r)                                                       \\
  for (int i = l; i <= r; i++)                                                 \\
    cout << vec[i] << " ";                                                     \\
  cout << endl;
#define forf(i, a, b) for (int i = (a); i < (b); i++)
#define forr(i, a, b) for (int i = (a); i > (b); i--)
#define input(vec, N)                                                          \\
  for (int i = 0; i < (N); i++)                                                \\
    cin >> vec[i];
#define debug(x) cerr << #x << " = " << (x) << endl;

// template starts
typedef long long int ll;
#define int ll
// template ends here
vector<int> S;
int N, K;
void solve() {
  // code starts from here
  cin >> N >> K;
  while (K--) {
    int l, r;
    cin >> l >> r;
    for (int i = l; i <= r; i++)
      S.pb(i);
  }

  sort(all(S));

  vector<int> dp(N + 1, 0);
  dp[1] = 1;
  int M = S.size();
  for (int i = 2; i <= N; i++) {
    for (int j = 0; j < M && S[j] < i; j++) {
      dp[i] += dp[i - S[j]];
      dp[i] %= MOD;
    }
  }
  cout << dp[N] << endl;
}

clock_t startTime;
double getCurrentTime() {
  return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  // startTime = clock();

  int T;
  // cin >> T;
  T = 1;
  while (T--) {
    solve();
  }

  // cout << getCurrentTime() << endl;
  return 0;
}

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

#define MOD (998244353)
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
#define nl '\\n'
#define all(x) x.begin(), x.end()
#define print(vec, l, r)                                                       \\
  for (int i = l; i <= r; i++)                                                 \\
    cout << vec[i] << " ";                                                     \\
  cout << endl;
#define forf(i, a, b) for (int i = (a); i < (b); i++)
#define forr(i, a, b) for (int i = (a); i > (b); i--)
#define input(vec, N)                                                          \\
  for (int i = 0; i < (N); i++)                                                \\
    cin >> vec[i];
#define debug(x) cerr << #x << " = " << (x) << endl;

// template starts
typedef long long int ll;
#define int ll
// template ends here
vector<int> S;
int N, K;
void solve() {
  // code starts from here
  cin >> N >> K;
  vector<pair<int, int>> ran;
  for (int k = 0; k < K; k++) {
    int l, r;
    cin >> l >> r;
    ran.pb(mp(l, r));
  }
  sort(all(ran));

  vector<int> dp(N + 1, 0);
  vector<int> p(N + 2, 0);
  dp[1] = 1;
  p[1] = 1;

  p[0] = 0;
  for (int i = 2; i <= N; i++) {
    int add = 0;
    for (int j = 0; j < K; j++) {
      if (ran[j].first >= i)
        break;

      int l = max((int)1, i - ran[j].second);
      int r = i - ran[j].first;

      add += p[r] - p[l - 1];
      // debug(p[ran[j].second]);
      add %= MOD;
      add += MOD;
      add %= MOD;
    }
    // debug(add);
    dp[i] = add;
    dp[i] %= MOD;
    p[i] = (p[i - 1] + dp[i]) % MOD;

    // print(dp,0,N);
    // print(p,0,N);
    // cerr << endl;
  }
  cout << dp[N] << endl;
}

clock_t startTime;
double getCurrentTime() {
  return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  // startTime = clock();

  int T;
  // cin >> T;
  T = 1;
  while (T--) {
    solve();
  }

  // cout << getCurrentTime() << endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
constexpr int MOD = 998244353;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, k;
  cin >> n >> k;
  vector<int> l(k), r(k);
  for (int i = 0; i < k; i++)
    cin >> l[i] >> r[i];
  vector<int> dp(2 * n + 100);
  // dp[1] = 1;
  // for (int i = 1; i < n; i++) {
  // 	for (int j = 0; j < k; j++) {
  // 		dp[i + l[j]] = dp[i];
  // 		dp[i + r[j] + 1] = -dp[i];
  // 	}
  // 	(dp[i] += dp[i - 1]) %= MOD;
  // }
  // for (int i = 1; i <= n; i++) {
  // }
  dp[1] = 1;
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < k; j++) {
      for (int kk = l[j]; kk <= min(n, r[j]); kk++) {
        (dp[i + kk] += dp[i]) %= MOD;
      }
    }
  }
  cout << dp[n] << "\\n";
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
constexpr int MOD = 998244353;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, k;
  cin >> n >> k;
  vector<int> l(k), r(k);
  for (int i = 0; i < k; i++)
    cin >> l[i] >> r[i];
  vector<long long> dp(2 * n + 100);
  dp[1] = 1;
  dp[2] = -1;
  for (int i = 1; i <= n; i++) {
    dp[i] = (dp[i] % MOD + MOD) % MOD;
    dp[i + 1] += dp[i];
    for (int j = 0; j < k; j++) {
      dp[i + l[j]] += dp[i];
      dp[i + r[j] + 1] -= dp[i];
    }
  }
  // dp[1] = 1;
  // for (int i = 1; i < n; i++) {
  // 	for (int j = 0; j < k; j++) {
  // 		for (int kk = l[j]; kk <= r[j]; kk++) {
  // 			(dp[i + kk] += dp[i]) %= MOD;
  // 		}
  // 	}
  // }
  cout << dp[n] << "\\n";
  return 0;
}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define pb(x) push_back(x)
#define mkp(x, y) make_pair(x, y)
#define L length()
#define int long long
#define bs binary_search
#define mod 1e9 + 7
#define IOS                                                                    \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define mem0(a) memset(a, 0, sizeof(a))
#define mem1(a) memset(a, -1, sizeof(a))
#define F first
#define S second
#define pii pair<int, int>
#define vi vector<int>
#define vs size()
#define endl '\\n'
#define atoi stoi
#define elasped_time 1.0 * clock() / CLOCKS_PER_SEC
#define si set<int>
#define vpii vector<pair<int, int>>
#define memf(a) memset(a, false, sizeof(a))
#define memt(a) memset(a, true, sizeof(a))
#define xxx 998244353
#define pi 3.141592653589
#define ninf INT_MIN
#define inf INT_MAX
#define sz(v) ((int)(v).size())
#define rep(i, a, b) for (int i = a; i <= b; i++)
int max(int a, int b) {
  if (a > b) {
    return a;
  } else {
    return b;
  }
}
int min(int a, int b) {
  if (a < b) {
    return a;
  } else {
    return b;
  }
}
int power(int b, int e) {
  if (e == 0)
    return 1;
  if (e % 2)
    return ((b * power((b) * (b), (e - 1) / 2)));
  else
    return power((b) * (b), e / 2);
}
int modpower(int b, int e, int q) {
  int MOD = q;
  if (e == 0)
    return 1;
  if (e % 2)
    return ((b % MOD) * modpower((b % MOD) * (b % MOD), (e - 1) / 2, q)) % MOD;
  else
    return modpower((b % MOD) * (b % MOD), e / 2, q) % MOD;
}
void dpv(vi v) {
  for (int i = 0; i < v.vs; i++) {
    cout << v[i] << " ";
  }
  cout << endl;
}
void dpv(vpii v) {
  for (int i = 0; i < v.vs; i++) {
    cout << v[i].F << " " << v[i].S << endl;
  }
}
void dpv(set<int> v) {
  for (auto i : v) {
    cout << i << " ";
  }
  cout << endl;
}
//////////////////////**TREE MOVES STARTS**//////////////////////////////
///// **TREE MOVES ENDS**////////////////////////////

////*SOLUTION TO THE QUESTION STARTS HERE*///////
vi pref(100001, 0);
vi dp(100001, 0);
int sum(int l, int r) {
  l = max(l, 0);
  return (pref[r] - (l == 0 ? 0 : pref[l - 1]));
}
void oblivious() {
  int m1 = 998244353;
  int n, k;
  cin >> n >> k;
  int l[k], r[k];
  pref[1] = 1;
  dp[1] = 1;
  for (int i = 0; i < k; i++) {
    cin >> l[i] >> r[i];
  }
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < k; j++) {
      if (i - l[j] >= 0) {
        int cur = sum(i - r[j], i - l[j]) % m1;
        dp[i] += cur % m1;
        dp[i] %= m1;
      }
    }
    pref[i] = (pref[i - 1] % m1 + dp[i] % m1) % m1;
  }
  dp[n] %= m1;
  cout << (dp[n] + m1) % m1 << endl;
}
signed main() {
  IOS;
  /*#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif*/
  int t = 1;
  // cin>>t;
  // int z=t;
  while (t--) {
    // cout<<"Case #"<<(z-t)<<": ";
    oblivious();
  }
  return 0;
}
// Editorial
/*

    */

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define pb(x) push_back(x)
#define mkp(x, y) make_pair(x, y)
#define L length()
#define int long long
#define bs binary_search
#define mod 1e9 + 7
#define IOS                                                                    \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define mem0(a) memset(a, 0, sizeof(a))
#define mem1(a) memset(a, -1, sizeof(a))
#define F first
#define S second
#define pii pair<int, int>
#define vi vector<int>
#define vs size()
#define endl '\\n'
#define atoi stoi
#define elasped_time 1.0 * clock() / CLOCKS_PER_SEC
#define si set<int>
#define vpii vector<pair<int, int>>
#define memf(a) memset(a, false, sizeof(a))
#define memt(a) memset(a, true, sizeof(a))
#define xxx 998244353
#define pi 3.141592653589
#define ninf INT_MIN
#define inf INT_MAX
#define sz(v) ((int)(v).size())
#define rep(i, a, b) for (int i = a; i <= b; i++)
int max(int a, int b) {
  if (a > b) {
    return a;
  } else {
    return b;
  }
}
int min(int a, int b) {
  if (a < b) {
    return a;
  } else {
    return b;
  }
}
int power(int b, int e) {
  if (e == 0)
    return 1;
  if (e % 2)
    return ((b * power((b) * (b), (e - 1) / 2)));
  else
    return power((b) * (b), e / 2);
}
int modpower(int b, int e, int q) {
  int MOD = q;
  if (e == 0)
    return 1;
  if (e % 2)
    return ((b % MOD) * modpower((b % MOD) * (b % MOD), (e - 1) / 2, q)) % MOD;
  else
    return modpower((b % MOD) * (b % MOD), e / 2, q) % MOD;
}
void dpv(vi v) {
  for (int i = 0; i < v.vs; i++) {
    cout << v[i] << " ";
  }
  cout << endl;
}
void dpv(vpii v) {
  for (int i = 0; i < v.vs; i++) {
    cout << v[i].F << " " << v[i].S << endl;
  }
}
void dpv(set<int> v) {
  for (auto i : v) {
    cout << i << " ";
  }
  cout << endl;
}
//////////////////////**TREE MOVES STARTS**//////////////////////////////
///// **TREE MOVES ENDS**////////////////////////////

////*SOLUTION TO THE QUESTION STARTS HERE*///////
vi pref(200001, 0);
vi dp(200001, 0);
int sum(int l, int r) {
  l = max(l, 0);
  return (pref[r] - (l == 0 ? 0 : pref[l - 1]));
}
void oblivious() {
  int m1 = 998244353;
  int n, k;
  cin >> n >> k;
  int l[k], r[k];
  pref[1] = 1;
  dp[1] = 1;
  for (int i = 0; i < k; i++) {
    cin >> l[i] >> r[i];
  }
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < k; j++) {
      if (i - l[j] >= 0) {
        int cur = sum(i - r[j], i - l[j]) % m1;
        dp[i] += cur % m1;
        dp[i] %= m1;
      }
    }
    pref[i] = (pref[i - 1] % m1 + dp[i] % m1) % m1;
  }
  dp[n] %= m1;
  cout << (dp[n] + m1) % m1 << endl;
}
signed main() {
  IOS;
  /*#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif*/
  int t = 1;
  // cin>>t;
  // int z=t;
  while (t--) {
    // cout<<"Case #"<<(z-t)<<": ";
    oblivious();
  }
  return 0;
}
// Editorial
/*

    */


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);
const ld EPS = 0.0000000001;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repd(i, n) for (ll i = n - 1; 0 <= i; i--)
#define FOR(i, a, b) for (ll i = a; i < (ll)(b); i++)
#define FORD(i, a, b) for (ll i = b - 1; (ll)(a) <= i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
string YES[2] = {"NO", "YES"};
string yes[2] = {"No", "Yes"};

int main() {
  ll n, k;
  cin >> n >> k;
  vector<pair<ll, ll>> seg(k);
  ll md = 998244353;
  vector<ll> csum(n + 2, 0);
  set<ll> key;
  rep(i, k) {
    ll a, b;
    cin >> a >> b;
    // a--, b--;
    seg[i] = {a, b};
    csum[a] += 1;
    csum[b + 1] -= 1;
  }

  rep(i, n + 2) {
    csum[i + 1] += csum[i];
    if (0 < csum[i + 1])
      key.insert(i + 1);
  }
  vector<ll> dp(n + 1, 0);
  dp[1] = 1;
  FOR(i, 1, n) {
    for (auto x : key) {
      if (n < i + x)
        break;
      dp[i + x] += dp[i];
      dp[i + x] %= md;
    }
  }
  // rep(i, n+1) cout << csum[i+1] << ' ';
  cout << dp[n] << endl;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);
const ld EPS = 0.0000000001;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repd(i, n) for (ll i = n - 1; 0 <= i; i--)
#define FOR(i, a, b) for (ll i = a; i < (ll)(b); i++)
#define FORD(i, a, b) for (ll i = b - 1; (ll)(a) <= i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
string YES[2] = {"NO", "YES"};
string yes[2] = {"No", "Yes"};

int main() {
  ll n, k;
  cin >> n >> k;
  vector<pair<ll, ll>> seg(k);
  ll md = 998244353;
  vector<ll> csum(n + 2, 0);
  set<pair<ll, ll>> key;
  rep(i, k) {
    ll a, b;
    cin >> a >> b;
    // a--, b--;
    seg[i] = {a, b};
    csum[a] += 1;
    csum[b + 1] -= 1;
    key.insert({a, b + 1});
  }

  // rep(i, n+2){
  //     csum[i+1] += csum[i];
  //     if(0<csum[i+1]) key.insert(i+1);
  // }
  // rep(i, n+1) cout << csum[i+1] << ' ';
  // cout << endl;
  vector<ll> dp(n + 2, 0);
  dp[1] = 1;
  FOR(i, 1, n) {
    // cout << i << endl;
    for (auto x : key) {
      ll a = min(i + x.first, n + 1), b = min(i + x.second, n + 1);
      dp[a] += dp[i];
      dp[b] -= dp[i];
      dp[a] = (dp[a] + md) % md;
      dp[b] = (dp[b] + md) % md;
      // rep(i, n+1) cout << dp[i+1] << ' ';
      // cout << endl;
    }
    if (i < n - 1)
      dp[i + 1] += dp[i];
    dp[i + 1] %= md;
  }
  // rep(i, n+1) cout << dp[i+1] << ' ';
  // cout << endl;
  // rep(i, n) dp[i+1] = (dp[i]+dp[i+1])%md;
  // rep(i, n+1) cout << dp[i+1] << ' ';
  // cout << endl;

  cout << dp[n] << endl;
}