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

const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a) {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a) {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(ll t) const {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint &operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream &operator>>(istream &is, mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> L(k);
  vector<int> R(k);
  rep(i, k) { cin >> L[i] >> R[i]; }
  vector<mint> dp(n, 0);
  vector<mint> dpsum(n, 0);
  dpsum[0] = 1;
  dp[0] = 1;
  for (int i = 1; i < n; i++) {
    rep(j, k) {
      if (i - L[j] < 0) {
        continue;
      } else if (i - R[i] - 1 < 0) {
        dp[i] += dpsum[i - L[j]];
      } else {
        dp[i] += dpsum[i - L[j]] - dpsum[i - R[j] - 1];
      }
    }
    dpsum[i] = dpsum[i - 1] + dp[i];
  }
  cout << dp[n - 1] << endl;
}

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

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a) {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a) {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(ll t) const {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint &operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream &operator>>(istream &is, mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }

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


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = LONG_LONG_MAX / 2;
const ll mod = 998244353;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main() {
  int N, K;
  cin >> N >> K;
  set<int> s;
  for (int i = 0; i < K; i++) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++) {
      s.insert(j);
    }
  }
  vector<int> v(s.size());
  copy(s.begin(), s.end(), v.begin());
  // for (int i : v) {
  //  cout << i << " ";
  //}
  // cout << endl;

  vector<ll> dp(N + 1, 0);
  dp[1] = 1;
  for (int i = 1; i < N; i++) {
    for (int j : v) {
      if (i + j > N)
        continue;
      dp[i + j] += dp[i];
      dp[i + j] %= mod;
    }
  }
  cout << dp[N] << endl;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = LONG_LONG_MAX / 2;
const ll mod = 998244353;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main() {
  int N, K;
  cin >> N >> K;
  vector<pair<int, int>> p;
  for (int i = 0; i < K; i++) {
    int l, r;
    cin >> l >> r;
    p.push_back(make_pair(l, r));
  }

  vector<ll> dp(2 * N + 1, 0);
  dp[1] = 1;
  for (int i = 1; i < N; i++) {
    dp[i] += dp[i - 1];
    dp[i] %= mod;
    for (auto j : p) {
      dp[i + j.first] += dp[i];
      dp[i + j.second + 1] -= dp[i];
      dp[i + j.first] %= mod;
      if (dp[i + j.second + 1] < 0)
        dp[i + j.second + 1] += mod;
    }
  }

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


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

#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/irange.hpp>
namespace adaptor = boost::adaptors;

// 多倍長テンプレ
/* ---------------------- ここから ---------------------- */
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;
/* ---------------------- ここまで ---------------------- */

using ll = long long;
using ull = unsigned long long;

ll dp[200010] = {0};

void Main() {
  ll N, K;
  cin >> N >> K;

  std::vector<ll> S;
  for (ll i = 0; i < K; ++i) {
    ll L, R;
    cin >> L >> R;
    for (ll j = L; j <= R; ++j) {
      S.push_back(j);
    }
  }

  dp[0] = 1;
  for (int i = 0; i < N; ++i) {
    if (dp[i] == 0) {
      continue;
    }
    for (int j = 0; j < (int)S.size(); ++j) {
      if (i + S[j] <= N) {
        dp[i + S[j]] = (dp[i + S[j]] + dp[i]) % 998244353;
      }
    }
  }

  cout << dp[N - 1];
  return;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
}

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

#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/irange.hpp>
namespace adaptor = boost::adaptors;

// 多倍長テンプレ
/* ---------------------- ここから ---------------------- */
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;
/* ---------------------- ここまで ---------------------- */

using ll = long long;
using ull = unsigned long long;

ll dp[200010] = {0};

void Main() {
  int N, K;
  cin >> N >> K;

  std::vector<pair<int, int>> S;
  for (int i = 0; i < K; ++i) {
    int L, R;
    cin >> L >> R;
    S.push_back({L, R});
  }

  dp[0] = 1;
  dp[1] = -1;
  for (int i = 0; i < N; ++i) {
    if (i > 0)
      dp[i] = (dp[i] + dp[i - 1]) % 998244353;
    for (int j = 0; j < (int)S.size(); ++j) {
      int l = S[j].first;
      int r = S[j].second;
      if (i + l <= N) {
        dp[i + l] = (dp[i + l] + dp[i]) % 998244353;
      }
      if (i + r + 1 <= N) {
        dp[i + r + 1] = (dp[i + r + 1] + 998244353 - dp[i]) % 998244353;
      }
    }
  }

  cout << dp[N - 1];
  return;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
}


#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
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;
}
// const ll INF = 1LL << 60;
// const int INF = 1001001001;

const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a) {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a) {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(ll t) const {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint &operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream &operator>>(istream &is, mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }

int main(void) {
  int n, k;
  cin >> n >> k;
  int l[k], r[k];
  REP(i, k) { cin >> l[i] >> r[i]; }
  set<int> s;
  REP(i, k) {
    for (int j = l[i]; j <= r[i]; j++)
      s.insert(j);
  }
  mint dp[n + 1];
  REP(i, n + 1) dp[i] = 0;
  dp[1] = 1;
  for (int i = 1; i <= n; i++) {
    for (auto j = s.begin(); j != s.end(); j++) {
      if (dp[i].x != 0)
        dp[i + *j] += dp[i];
    }
  }
  cout << dp[n];
  return 0;
}

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
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;
}
// const ll INF = 1LL << 60;
// const int INF = 1001001001;

const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a) {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a) {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(ll t) const {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint &operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream &operator>>(istream &is, mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }
int main(void) {
  int n, k;
  cin >> n >> k;
  vector<int> l(k), r(k);
  REP(i, k) cin >> l[i] >> r[i];
  vector<mint> dp(n + 1);
  vector<mint> dpsum(n + 1);
  dp[1] = 1;
  dpsum[1] = 1;
  for (int i = 2; i <= n; i++) {
    REP(j, k) {
      //[l[j],r[j]]
      int li = i - r[j];
      int ri = i - l[j];
      if (ri < 0)
        continue;
      li = max(li, 1);
      dp[i] += dpsum[ri] - dpsum[li - 1]; // dp[li]~dp[ri]
    }
    dpsum[i] = dpsum[i - 1] + dp[i];
  }
  cout << dp[n] << endl;
  return 0;
}


#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;
const int mod = 998244353;
int n, k;

int main() {
  scanf("%d %d", &n, &k);
  vector<pair<int, int>> s;
  for (int i = 0; i < k; ++i) {
    int l, r;
    scanf("%d %d", &l, &r);
    s.push_back({l, r});
  }
  sort(s.begin(), s.end());

  // cnt[i] := the number of possible ways to reach ith cell
  // cnt[i] = sum{cnt[i-k] | k in S}
  vector<long long> cnt(n + 1, 0);
  cnt[1] = 1;
  for (int i = 2; i <= n; ++i) {
    for (auto it : s) {
      for (int k = it.first; k <= it.second; ++k) {
        if (i - k <= 0) {
          break;
        }
        cnt[i] += cnt[i - k];
      }
      cnt[i] %= mod;
    }
  }
  printf("%lld\\n", cnt[n]);
  return 0;
}

#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;
const int mod = 998244353;
int n, k;

int main() {
  scanf("%d %d", &n, &k);
  vector<pair<int, int>> s;
  for (int i = 0; i < k; ++i) {
    int l, r;
    scanf("%d %d", &l, &r);
    s.push_back({l, r});
  }

  vector<long long> dp(n + 1, 0);
  vector<long long> preSum(n + 1, 0);
  dp[1] = 1;
  preSum[1] = 1;
  for (int i = 2; i <= n; ++i) {
    for (int j = 0; j < k; ++j) {
      int l = i - s[j].second;
      int r = i - s[j].first;
      if (r < 0)
        continue;
      l = max(1, l);
      dp[i] += preSum[r] - preSum[l - 1];
      dp[i] %= mod;
    }
    preSum[i] = preSum[i - 1] + dp[i];
  }
  printf("%lld\\n", dp[n]);
  return 0;

  sort(s.begin(), s.end());
  // cnt[i] := the number of possible ways to reach ith cell
  // cnt[i] = sum{cnt[i-k] | k in S}
  vector<long long> cnt(n + 1, 0);
  cnt[1] = 1;
  for (int i = 2; i <= n; ++i) {
    for (auto it : s) {
      for (int k = it.first; k <= it.second; ++k) {
        if (i - k <= 0) {
          break;
        }
        cnt[i] += cnt[i - k];
      }
      cnt[i] %= mod;
    }
  }
  printf("%lld\\n", cnt[n]);
  return 0;
}


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

template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

// typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;

// container util
//------------------------------------------
#define PB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
// repetition
//------------------------------------------
#define FOR(i, a, b) for (LL i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define ALL(a) (a).begin(), (a).end()
// constant
//--------------------------------------------
// clear memory
#define CLR(a) memset((a), 0, sizeof(a))
LL dp[200003];
LL mod = 998244353;
int main() {
  int N, K;
  cin >> N >> K;
  vector<int> S;
  REP(i, K) {
    int L, R;
    cin >> L >> R;
    FOR(ii, L, R + 1) S.PB(ii);
  }
  SORT(S);
  CLR(dp);
  dp[1] = 1;
  FOR(i, 1, N + 1) {
    REP(k, SZ(S)) if (i >= S[k]) { dp[i] = (dp[i] + dp[i - S[k]]) % mod; }
  }
  cout << dp[N] % mod << endl;
  return 0;
}

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

template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

// typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;

// container util
//------------------------------------------
#define PB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
// repetition
//------------------------------------------
#define FOR(i, a, b) for (LL i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define ALL(a) (a).begin(), (a).end()
// constant
//--------------------------------------------
// clear memory
#define CLR(a) memset((a), 0, sizeof(a))
LL dp[400003];
LL sum[200003];
LL mod = 998244353;
static const int MAX_SIZE = 1 << 20;

LL all[2 * MAX_SIZE - 1], part[2 * MAX_SIZE - 1];

void add(int a, int b, LL x, int k = 0, int l = 0, int r = MAX_SIZE) {
  if (a <= l && r <= b) {
    all[k] += x;
  } else if (l < b && a < r) {
    part[k] += (min(b, r) - max(a, l)) * x;
    add(a, b, x, k * 2 + 1, l, (l + r) / 2);
    add(a, b, x, k * 2 + 2, (l + r) / 2, r);
  }
}
LL sum2(int a, int b, int k = 0, int l = 0, int r = MAX_SIZE) {
  if (b <= l || r <= a) {
    return (0);
  } else if (a <= l && r <= b) {
    return (all[k] * (r - l) + part[k]);
  } else {
    LL res = (min(b, r) - max(a, l)) * all[k];
    res += sum2(a, b, k * 2 + 1, l, (l + r) / 2);
    res += sum2(a, b, k * 2 + 2, (l + r) / 2, r);
    return (res);
  }
}
int main() {
  CLR(all);
  CLR(part);
  int N, K;
  cin >> N >> K;
  vector<PII> pi;
  REP(i, K) {
    int L, R;
    cin >> L >> R;
    pi.PB(MP(L, R));
  }
  CLR(dp);
  // dp[0]=1;
  add(1, 2, 1);
  FOR(i, 1, N + 1) {
    REP(k, SZ(pi)) {
      int s = pi[k].first;
      int e = pi[k].second;
      LL addval = sum2(i, i + 1) % mod;
      add(i + s, i + e + 1, addval);
    }
  }
  cout << sum2(N, N + 1) % mod << endl;
  return 0;
}


#include <bits/stdc++.h>
#define ll long long int
#define all(x) x.begin(), x.end()
using namespace std;
ll power(ll x, ll y, ll m) {
  if (y == 0)
    return 1;
  ll p = power(x, y / 2, m) % m;
  p = (p * p) % m;

  return (y % 2 == 0) ? p : (x * p) % m;
}
ll modInverse(ll a, ll m) {
  ll g = __gcd(a, m);
  if (g != 1)
    cout << "Inverse doesn't exist";

  // If a and m are relatively prime, then modulo inverse
  // is a^(m-2) mode m

  return power(a, m - 2, m);
}

ll fact[1000];
void fac(ll m) {
  ll i;
  fact[0] = 1;
  for (i = 1; i < 1000; i++) {
    fact[i] = (i * fact[i - 1]) % m;
  }
}

ll comb(ll n, ll k, ll m) {
  return (fact[n] * modInverse(fact[k], m) % m * modInverse(fact[n - k], m) %
          m) %
         m;
}
bool cmp(pair<ll, ll> a, pair<ll, ll> b) {
  if (a.second == b.second)
    return a.first < b.first;
  return a.second > b.second;
}
void SieveOfEratosthenes(ll n) {
  // Create a boolean array "prime[0..n]" and initialize
  // all entries it as true. A value in prime[i] will
  // finally be false if i is Not a prime, else true.
  bool prime[n + 1];
  memset(prime, true, sizeof(prime));

  for (ll p = 2; p * p <= n; p++) {
    // If prime[p] is not changed, then it is a prime
    if (prime[p] == true) {
      // Update all multiples of p greater than or
      // equal to the square of it
      // numbers which are multiple of p and are
      // less than p^2 are already been marked.
      for (ll i = p * p; i <= n; i += p)
        prime[i] = false;
    }
  }
}
/*ll f(ll a)
{
ll i;ll res=1;ll c;
for(i=2;i*i<=a;i++)
{
        if(a%i==0)
        {
                c=0;
                while(a%i==0)
                {
                        c++;
                        a=a/i;
                }

        }
        if(c>0)
        {
                res*=(c+1);
        }
}
        if(a>1)
        {
                res*=2;
        }

        return res;
}*/
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n, k;
  cin >> n >> k;
  ll mod = 998244353;
  ll i;
  ll pre[100001] = {0};
  ll dp[100001] = {0};
  vector<pair<ll, ll>> a;
  for (i = 0; i < k; i++) {
    ll l, r;
    cin >> l >> r;
    a.push_back({l, r});
  }
  sort(all(a));
  dp[1] = 1;
  pre[1] = 1;
  ll j;
  for (i = 2; i <= n; i++) {
    for (j = 0; j < k; j++) {
      if (a[j].first > i) {
        continue;
      } else if (a[j].second < i) {
        dp[i] = (dp[i] + pre[i - a[j].first] - pre[i - a[j].second - 1] + mod) %
                mod;
      } else {
        dp[i] = (dp[i] + pre[i - a[j].first] - pre[0] + mod) % mod;
      }
    }
    pre[i] = (pre[i - 1] + dp[i]) % mod;
  }

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

#include <bits/stdc++.h>

#define FLASH                                                                  \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define int long long int
#define MAX 1e9
#define MIN -1e9
#define mod 998244353
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr << #x << '=' << (x) << endl;
#define output(x) cout << (x ? "Yes" : "No") << '\\n';
#define mxn 100005
using namespace std;

void solve() {
  int n, k;
  cin >> n >> k;
  int l[k], r[k];
  for (int i = 0; i < k; i++) {
    cin >> l[i] >> r[i];
  }
  int dp[n + 5] = {};
  int pref[n + 5] = {};
  dp[1] = 1;
  pref[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < k; j++) {
      if (i <= l[j])
        continue;

      int left = l[j];
      int right = min(r[j], i - 1);
      int val = (pref[i - left] - pref[i - right - 1] + mod) % mod;

      dp[i] = (dp[i] + val) % mod;
    }
    pref[i] = (pref[i - 1] % mod + dp[i] % mod) % mod;
  }
  cout << dp[n];
}

int32_t main() {
  FLASH
  int t = 1;
  // cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}


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

#define REP(i, begin, end)                                                     \\
  for (__typeof(end) i = (begin) - ((begin) > (end));                          \\
       i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define ALL(c) c.begin(), c.end()
#define SZ(c) (int)c.size()
#define DBG1(x) cout << #x << " = " << x << "\\n"
#if USE_CP_REDIR
#define CP                                                                     \\
  freopen("input.txt", "r", stdin);                                            \\
  freopen("output.txt", "w", stdout);
#endif

using ll = long long;
using pii = pair<int, int>;

const ll MOD = 998244353;
const int MN = 200'000;
int N, K;
ll DP[MN + 100];

ll add(ll a, ll b) {
  a %= MOD;
  b %= MOD;
  return (a + b) % MOD;
}

ll cnt(int i, const vector<pii> &S) {
  if (i == N)
    return 1LL;
  if (i > N)
    return 0LL;

  ll &ans = DP[i];
  if (ans != -1)
    return ans;

  ans = 0LL;
  for (const pii &s : S) {
    for (int d = s.first; d <= s.second; d++) {
      if (i + d > N)
        goto fim;
      ans = add(ans, cnt(i + d, S));
    }
  }
fim:
  return ans;
}

ll cnt2(const vector<pii> &S) {
  DP[N] = 1;
  for (register int i = N - 1; i > 0; i--) {
    for (const pii &s : S) {
      for (int d = s.first; d <= s.second; d++) {
        if (i + d > N)
          goto outer;
        DP[i] = add(DP[i], DP[i + d]);
      }
    }
  outer:;
  }
  return DP[1];
}

int main() {
  ios::sync_with_stdio(false);
#ifdef CP
  CP;
#endif
  cin >> N >> K;
  vector<pii> S(K);
  REP(i, 0, K) cin >> S[i].first >> S[i].second;
  memset(DP, 0, sizeof DP);
  sort(ALL(S));
  cout << cnt2(S) << endl;
}

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

#define REP(i, begin, end)                                                     \\
  for (__typeof(end) i = (begin) - ((begin) > (end));                          \\
       i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define ALL(c) c.begin(), c.end()
#define SZ(c) (int)c.size()
#define DBG1(x) cout << #x << " = " << x << "\\n"
#if USE_CP_REDIR
#define CP                                                                     \\
  freopen("input.txt", "r", stdin);                                            \\
  freopen("output.txt", "w", stdout);
#endif

using ll = long long;
using pii = pair<int, int>;

const ll MOD = 998244353;
const int MN = 200'000;
int N, K;
ll DP[MN + 2];
ll DPSUM[MN + 2];

ll ADD(ll a, ll b) {
  a %= MOD;
  b %= MOD;
  return (a + b) % MOD;
}

ll cnt2(const vector<pii> &S) {
  DP[N] = 1;
  DPSUM[N] = 1;
  for (int i = N - 1; i > 0; i--) {
    for (const pii &s : S) {
      int l = i + s.first;
      int r = min(N, i + s.second);
      if (l > N)
        continue;
      DP[i] = ADD(DP[i], ADD(DPSUM[l], MOD - DPSUM[r + 1]));
    }
    DPSUM[i] = ADD(DPSUM[i + 1], DP[i]);
  }
  return DP[1];
}

int main() {
  ios::sync_with_stdio(false);
#ifdef CP
  CP;
#endif
  cin >> N >> K;
  vector<pii> S(K);
  REP(i, 0, K) cin >> S[i].first >> S[i].second;
  memset(DP, 0, sizeof DP);
  sort(ALL(S));
  cout << cnt2(S) << endl;
}


#include <cstdint>
#include <iostream>
#include <set>
#include <utility>
#include <vector>

using namespace std;

constexpr int64_t kMod = 998244353;

struct Step {
  int64_t from;
  int64_t left;
  int64_t right;
  int64_t pattern;
};

int main() {
  int64_t N, K;
  cin >> N >> K;

  vector<pair<int64_t, int64_t>> ranges;
  ranges.reserve(10);
  for (int64_t k = 0; k < K; ++k) {
    int64_t l, r;
    cin >> l >> r;
    ranges.push_back({l, r});
  }
  vector<Step> steps;
  int64_t step = 1;
  for (int64_t n = 1; n <= N; ++n) {
    set<int64_t> froms;
    if (n != 1)
      step = 0;
    for (auto it = steps.begin(); it != steps.end();) {
      if (froms.count((*it).from)) {
        ++it;
        continue;
      }
      if ((*it).left <= n && n <= (*it).right) {
        step += (*it).pattern;
        step %= kMod;
        froms.insert((*it).from);
      }
      if ((*it).right == n) {
        it = steps.erase(it);
      } else {
        ++it;
      }
    }
    if (n != N) {
      for (auto &range : ranges) {
        steps.push_back({n, n + range.first, n + range.second, step});
      }
    }
  }
  cout << step << endl;

  return 0;
}

#include <cstdint>
#include <iostream>
#include <set>
#include <utility>
#include <vector>

using namespace std;

template <typename T, T kMod> struct ModInt {
  using M = ModInt;
  T v;

  ModInt(T _v = 0) { set_norm(_v % kMod + kMod); }
  M &set_norm(T _v) {
    v = (_v < kMod) ? _v : _v - kMod;
    return *this;
  }

  explicit operator bool() const { return v != 0; }
  M operator+(const M &a) const { return M().set_norm(v + a.v); }
  M operator-(const M &a) const { return M().set_norm(v + kMod - a.v); }
  M operator*(const M &a) const { return M().set_norm(ull(v) * a.v % kMod); }
  M operator/(const M &a) const { return *this * a.inv(); }
  M &operator+=(const M &a) { return *this = *this + a; }
  M &operator-=(const M &a) { return *this = *this - a; }
  M &operator*=(const M &a) { return *this = *this * a; }
  M &operator/=(const M &a) { return *this = *this / a; }
  M operator-() const { return M() - *this; }
  M &operator++(int) { return *this = *this + 1; }
  M &operator--(int) { return *this = *this - 1; }

  M pow(T n) const {
    if (n < 0)
      return inv().pow(-n);
    M x = *this, res = 1;
    while (n) {
      if (n & 1)
        res *= x;
      x *= x;
      n >>= 1;
    }
    return res;
  }

  M inv() const {
    T a = v, b = kMod, p = 1, q = 0, t;
    while (b != 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(p -= t * q, q);
    }
    return M(p);
  }

  bool operator==(const M &a) const { return v == a.v; }
  bool operator!=(const M &a) const { return v != a.v; }
  friend ostream &operator<<(ostream &os, const M &a) { return os << a.v; }
  static T get_mod() { return kMod; }
};

using MInt = ModInt<int64_t, 998244353>;

struct Step {
  int64_t from;
  int64_t left;
  int64_t right;
  int64_t pattern;
};

int main() {
  int64_t N, K;
  cin >> N >> K;

  vector<pair<int64_t, int64_t>> ranges;
  ranges.reserve(10);
  for (int64_t k = 0; k < K; ++k) {
    int64_t l, r;
    cin >> l >> r;
    ranges.push_back({l, r + 1});
  }
  vector<MInt> dp(N + 1);
  dp[1] = 1;
  dp[2] = -1;
  for (int64_t n = 1; n <= N; ++n) {
    dp[n] += dp[n - 1];
    for (auto &range : ranges) {
      if (n + range.first <= N) {
        dp[n + range.first] += dp[n];
      }
      if (n + range.second <= N) {
        dp[n + range.second] -= dp[n];
      }
    }
  }
  cout << dp[N] << endl;

  return 0;
}


#include <algorithm>
#include <bitset>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;
const long long ll_max = 9223372036854775807;
const long long ll_min = -9223372036854775807;
const int int_max = 2147483647;

template <typename T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

template <typename T> map<T, T> getPrimeFactor(T n) {
  map<T, T> ret;
  for (T i = 2; i * i <= n; ++i) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1)
    ret[n] = 1;
  return ret;
}

template <typename T> bool IsPrimeNumber(T num) {
  if (num <= 2)
    return true;
  else if (num % 2 == 0)
    return false;

  double sqrtNum = sqrt(num);
  for (int i = 3; i <= sqrtNum; i += 2) {
    if (num % i == 0) {
      return false;
    }
  }

  return true;
}

template <typename T> T modinv(T a, T m) {
  T b = m, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0)
    u += m;
  return u;
}

// 繰り返し二乗法
ll pow2(ll n, ll p, ll mod) {
  if (p == 0 || n == 1) {
    return 1;
  } else {
    ll ret = pow2(n * n % mod, p / 2, mod);
    if (p % 2 == 1) {
      ret *= n;
    }
    return ret % mod;
  }
}

#define rep(i, s, e) for (ll i = s; i < e; i++)
#define repeq(i, s, e) for (ll i = s; i <= e; i++)

ll n;
vector<pair<ll, ll>> t;
const ll mod = 998244353;
map<ll, ll> dic;
ll func(ll pos) {
  auto itr = dic.find(pos);
  if (itr != dic.end()) {
    return itr->second;
  }
  ll ret = 0;
  for (auto x : t) {
    repeq(y, x.first, x.second) {
      if (pos + y == n) {
        ret++;
      } else if (pos + y < n) {
        ret += func(pos + y);
      }
      ret %= mod;
    }
  }
  dic[pos] = ret;
  return ret;
}

int main() {

  ll k;
  cin >> n >> k;

  t.resize(k);
  rep(i, 0, k) { cin >> t[i].first >> t[i].second; }

  cout << func(1) << endl;
  return 0;
}

#include <algorithm>
#include <bitset>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;
const long long ll_max = 9223372036854775807;
const long long ll_min = -9223372036854775807;
const int int_max = 2147483647;

template <typename T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

template <typename T> map<T, T> getPrimeFactor(T n) {
  map<T, T> ret;
  for (T i = 2; i * i <= n; ++i) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1)
    ret[n] = 1;
  return ret;
}

template <typename T> bool IsPrimeNumber(T num) {
  if (num <= 2)
    return true;
  else if (num % 2 == 0)
    return false;

  double sqrtNum = sqrt(num);
  for (int i = 3; i <= sqrtNum; i += 2) {
    if (num % i == 0) {
      return false;
    }
  }

  return true;
}

template <typename T> T modinv(T a, T m) {
  T b = m, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0)
    u += m;
  return u;
}

// 繰り返し二乗法
ll pow2(ll n, ll p, ll mod) {
  if (p == 0 || n == 1) {
    return 1;
  } else {
    ll ret = pow2(n * n % mod, p / 2, mod);
    if (p % 2 == 1) {
      ret *= n;
    }
    return ret % mod;
  }
}

#define rep(i, s, e) for (ll i = s; i < e; i++)
#define repeq(i, s, e) for (ll i = s; i <= e; i++)

int main() {
  const ll mod = 998244353;
  ll n, k;
  cin >> n >> k;

  vll t(n + 1, 0);
  vector<pair<ll, ll>> vp(k);
  rep(i, 0, k) { cin >> vp[i].first >> vp[i].second; }

  t[1] = 1;
  repeq(i, 2, n) {
    t[i] = t[i - 1];
    rep(j, 0, k) {
      ll tmp = t[max(0LL, i - vp[j].first)] - t[max(0LL, i - vp[j].second - 1)];
      if (tmp < 0) {
        tmp += mod;
      }
      t[i] += tmp;
      t[i] %= mod;
    }
  }

  ll ans = t[n] - t[n - 1];
  if (ans < 0) {
    ans += mod;
  }
  cout << ans << endl;
  return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define pii pair<ll int, ll int>
#define PI 2 * acos(0)
// #define mx 1000000
#define INF LONG_LONG_MAX
using namespace std;
const ll int p = 998244353;
// vector<ll > prime;
// bool mark[mx];
ll int mod(ll int a, ll int b) {
  ll int m = a % b;
  if (m < 0)
    m = (b < 0) ? (m - b) : (m + b);
  return m;
}
ll maxpow(ll n) { return (n & (~(n - 1))); }
bool isPrime(ll n) {
  if (n < 2)
    return false;
  if (n == 2)
    return true;
  if (n % 2 == 0)
    return false;
  for (ll i = 3; i * i <= n; i += 2) {
    if (n % i == 0)
      return false;
  }
  return true;
}
/*void init()
{
    mark[1]=1;
    int i,j,limit=sqrt(mx*1.0)+2;
    prime.push_back(2);
    for(i=4;i<mx;i+=2) mark[i]=1;
    mark[2]=0;
    for(i=3;i<mx;i+=2){
        if(!mark[i]){
            prime.push_back(i);
            if(i<=limit){
                for(j=i*i;j<mx;j+=2*i){
                    mark[j]=1;
                }
            }
        }
    }
}*/
/*
ll maxdiv(ll n)
{
    ll i,ans=1;
    for(i=0;i<prime.size();i++){
        if(n%prime[i]==0){
            ans=n/prime[i];break;
            //return ans;
        }
    }
    return ans;
}*/
ll lcm(ll a, ll b) {
  ll ans = a * b;
  return (ans / __gcd(a, b));
}
// ax+by and a>b
ll gcd(ll a, ll b, ll &x, ll &y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  ll x1, y1;
  ll d = gcd(b, mod(a, b), x1, y1);
  x = y1;
  y = x1 - y1 * (a / b);
  return d;
}
ll abso(ll a) {
  if (a >= 0)
    return a;
  return -a;
}
ll div_count(ll n) {
  bool flag[n + 1];
  memset(flag, 1, sizeof(flag));
  for (int p = 2; p * p < n; p++) {
    if (flag[p]) {
      for (int i = p * 2; i < n; i += p)
        flag[i] = false;
    }
  }
  ll total = 1;
  for (int p = 2; p <= n; p++) {
    if (flag[p]) {
      int cnt = 0;
      while (n % p == 0) {
        n /= p;
        cnt++;
      }
      total *= (cnt + 1);
    }
  }
  return total;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  ll n, k;
  cin >> n >> k;
  ll dp[n + 1], l[k + 1], r[k + 1];
  memset(dp, 0, sizeof(dp));
  for (int i = 1; i <= k; i++)
    cin >> l[i] >> r[i];
  dp[1] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= k; j++) {
      for (int in = l[j]; in <= r[j]; in++) {
        if (i + in <= n) {
          dp[i + in] += mod(dp[i], p);
          dp[i + in] = mod(dp[i + in], p);
        }
      }
    }
  }
  cout << dp[n] % p;
  return 0;
}
// 1028C

#include <bits/stdc++.h>
#define ll long long
#define pii pair<ll int, ll int>
#define PI 2 * acos(0)
// #define mx 1000000
#define INF LONG_LONG_MAX
using namespace std;
const ll int p = 998244353;
// vector<ll > prime;
// bool mark[mx];
ll int mod(ll int a, ll int b) {
  ll int m = a % b;
  if (m < 0)
    m = (b < 0) ? (m - b) : (m + b);
  return m;
}
ll maxpow(ll n) { return (n & (~(n - 1))); }
bool isPrime(ll n) {
  if (n < 2)
    return false;
  if (n == 2)
    return true;
  if (n % 2 == 0)
    return false;
  for (ll i = 3; i * i <= n; i += 2) {
    if (n % i == 0)
      return false;
  }
  return true;
}
/*void init()
{
    mark[1]=1;
    int i,j,limit=sqrt(mx*1.0)+2;
    prime.push_back(2);
    for(i=4;i<mx;i+=2) mark[i]=1;
    mark[2]=0;
    for(i=3;i<mx;i+=2){
        if(!mark[i]){
            prime.push_back(i);
            if(i<=limit){
                for(j=i*i;j<mx;j+=2*i){
                    mark[j]=1;
                }
            }
        }
    }
}*/
/*
ll maxdiv(ll n)
{
    ll i,ans=1;
    for(i=0;i<prime.size();i++){
        if(n%prime[i]==0){
            ans=n/prime[i];break;
            //return ans;
        }
    }
    return ans;
}*/
ll lcm(ll a, ll b) {
  ll ans = a * b;
  return (ans / __gcd(a, b));
}
// ax+by and a>b
ll gcd(ll a, ll b, ll &x, ll &y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  ll x1, y1;
  ll d = gcd(b, mod(a, b), x1, y1);
  x = y1;
  y = x1 - y1 * (a / b);
  return d;
}
ll abso(ll a) {
  if (a >= 0)
    return a;
  return -a;
}
ll div_count(ll n) {
  bool flag[n + 1];
  memset(flag, 1, sizeof(flag));
  for (int p = 2; p * p < n; p++) {
    if (flag[p]) {
      for (int i = p * 2; i < n; i += p)
        flag[i] = false;
    }
  }
  ll total = 1;
  for (int p = 2; p <= n; p++) {
    if (flag[p]) {
      int cnt = 0;
      while (n % p == 0) {
        n /= p;
        cnt++;
      }
      total *= (cnt + 1);
    }
  }
  return total;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  ll n, k;
  cin >> n >> k;
  ll dp[n + 1], l[k + 1], r[k + 1], pref[n + 1];
  memset(dp, 0, sizeof(dp));
  memset(pref, 0, sizeof(pref));
  for (int i = 1; i <= k; i++)
    cin >> l[i] >> r[i];
  dp[1] = 1;
  dp[0] = 0;
  pref[1] = 1;
  pref[0] = 0;
  for (int i = 2; i <= n; i++) {
    for (int j = 1; j <= k; j++) {
      if (i >= l[j])
        dp[i] += mod(pref[i - l[j]], p);
      if (i > r[j])
        dp[i] -= mod(pref[i - r[j] - 1], p);
      dp[i] = mod(dp[i], p);
    }
    pref[i] = mod(pref[i - 1] + dp[i], p);
  }
  cout << dp[n];
  return 0;
}
// 1028C


#include <cstring>
#include <iostream>
#include <vector>

#define MODULO 998244353

using namespace std;

vector<int> moveDistances;
long long moveCountCache[200001] = {0, 1};

int main() {
  int n;
  int k;

  scanf("%d%d", &n, &k);

  for (int i = 0; i < k; i++) {
    int leftEnd;
    int rightEnd;

    scanf("%d%d", &leftEnd, &rightEnd);

    for (int j = leftEnd; j <= rightEnd; j++) {
      moveDistances.push_back(j);
    }
  }

  for (int i = 2; i <= n; i++) {
    for (int moveDistance : moveDistances) {
      moveCountCache[i] =
          (moveCountCache[i] +
           (i - moveDistance > 0 ? moveCountCache[i - moveDistance] : 0)) %
          MODULO;
    }
  }

  printf("%d\\n", moveCountCache[n]);

  return 0;
}

#include <cstring>
#include <iostream>
#include <vector>

#define MODULO 998244353

using namespace std;

long long moveCountCache[200001] = {0, 1};
long long moveCountSumCache[200001] = {0, 1};

int main() {
  int n;
  int k;

  cin >> n >> k;

  vector<pair<int, int>> moveSegments(k);

  for (int i = 0; i < k; i++) {
    cin >> moveSegments[i].first >> moveSegments[i].second;
  }

  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < k; j++) {
      int leftEndIndex = max(i - moveSegments[j].second, 1);
      int rightEndIndex = i - moveSegments[j].first;

      if (rightEndIndex < 0)
        continue;

      moveCountCache[i] += moveCountSumCache[rightEndIndex] -
                           moveCountSumCache[leftEndIndex - 1];
      moveCountCache[i] %= MODULO;
    }

    moveCountSumCache[i] = moveCountSumCache[i - 1] + moveCountCache[i];
  }

  cout << moveCountCache[n] << endl;

  return 0;
}


#include <bits/stdc++.h>
#define ll long long int
#define N int(1e5 + 10)
#define mod 998244353
using namespace std;
ll dp[N], pre[N];
int l[N], r[N], n, k;
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cout.precision(10);
  cin >> n >> k;
  for (int i = 1; i <= k; i++)
    cin >> l[i] >> r[i];
  pre[0] = dp[0] = 0ll;
  pre[1] = dp[1] = 1ll;
  for (int i = 2; i <= n; i++) {
    dp[i] = 0ll;
    for (int j = 1, u, v; j <= k; j++) {
      if (l[j] >= i)
        continue;
      u = l[j];
      v = min(i - 1, r[j]);
      dp[i] = ((dp[i] + pre[i - u]) % mod - pre[i - v - 1]) % mod;
      if (dp[i] < 0ll)
        dp[i] += mod;
    }
    pre[i] = (pre[i - 1] + dp[i]) % mod;
  }
  cout << dp[n] << endl;
  return 0;
}

#include <bits/stdc++.h>
#define ll long long int
#define N int(2e5 + 10)
#define mod 998244353
using namespace std;
ll dp[N], pre[N];
int l[N], r[N], n, k;
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cout.precision(10);
  cin >> n >> k;
  for (int i = 1; i <= k; i++)
    cin >> l[i] >> r[i];
  pre[0] = dp[0] = 0ll;
  pre[1] = dp[1] = 1ll;
  for (int i = 2; i <= n; i++) {
    dp[i] = 0ll;
    for (int j = 1, u, v; j <= k; j++) {
      if (l[j] >= i)
        continue;
      u = l[j];
      v = min(i - 1, r[j]);
      dp[i] = ((dp[i] + pre[i - u]) % mod - pre[i - v - 1]) % mod;
      if (dp[i] < 0ll)
        dp[i] += mod;
    }
    pre[i] = (pre[i - 1] + dp[i]) % mod;
  }
  cout << dp[n] << endl;
  return 0;
}


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

using namespace std;

#define ll long long int
#define ld long double
#define pb push_back
#define all(v) v.begin(), v.end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
#define deb(x) cout << #x << '=' << x << endl
#define MOD 998244353
const int N = 2e5 + 5;
int dp[N];
int b[N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int n, k;
  cin >> n >> k;
  set<int> S;
  for (int i = 0; i < k; i++) {
    int l, r;
    cin >> l >> r;
    b[l]++;
    b[r + 1]--;
  }
  for (int i = 1; i <= n; i++) {
    b[i] += b[i - 1];
  }
  for (int i = 1; i <= n; i++) {
    if (b[i] > 0) {
      S.insert(i);
    }
  }
  dp[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (auto j : S) {
      if (i - j > 0) {
        dp[i] += dp[i - j];
        dp[i] %= MOD;
      }
    }
  }
  cout << dp[n] << "\\n";
}

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

using namespace std;

#define ll long long int
#define ld long double
#define pb push_back
#define all(v) v.begin(), v.end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
#define deb(x) cout << #x << '=' << x << endl
#define MOD 998244353
const int N = 2e5 + 5;
int dp[N];
int pref[N], l[N], r[N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int n, k;
  cin >> n >> k;
  for (int i = 0; i < k; i++) {
    cin >> l[i] >> r[i];
  }
  dp[1] = 1;
  pref[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < k; j++) {
      if (i <= l[j]) {
        continue;
      }
      int left = l[j];
      int right = min(r[j], i - 1);
      int add = (pref[i - left] - pref[i - right - 1] + MOD) % MOD;
      dp[i] = (dp[i] + add) % MOD;
    }
    pref[i] = pref[i - 1] + dp[i];
    pref[i] %= MOD;
  }
  cout << dp[n] << "\\n";
}


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

const int MOD = 998244353;

int main() {
  int N, K;
  cin >> N >> K;

  vector<long long> dp(N + 10);
  set<long long> s;
  for (long long i = 0; i < K; ++i) {
    long long L, R;
    cin >> L >> R;
    for (long long j = L; j <= R; ++j) {
      s.insert(j);
    }
  }

  dp[0] = 1;
  for (int i = 0; i < N + 10; ++i) {
    for (auto num : s) {
      if (i + num < N + 10) {
        dp[i + num] += dp[i];
        dp[i + num] %= MOD;
      }
    }
  }

  cout << dp[N - 1] << endl;
}

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

const int MOD = 998244353;

int main() {
  int N, K;
  cin >> N >> K;

  set<long long> s;
  vector<long long> l(K);
  vector<long long> r(K);

  for (long long i = 0; i < K; ++i) {
    cin >> l[i] >> r[i];
  }

  vector<long long> dp(N + 10);
  vector<long long> dp_sum(N + 10);

  dp[1] = 1;
  dp_sum[1] = 1;

  for (int i = 2; i < N + 10; ++i) {
    for (int j = 0; j < K; ++j) {
      int li = i - r[j];
      int ri = i - l[j];
      if (ri < 0)
        continue;
      li = max(1, li);
      long long tmp = dp_sum[ri] - dp_sum[li - 1];
      if (tmp < 0)
        tmp += MOD;
      dp[i] += tmp;
      dp[i] %= MOD;
    }
    dp_sum[i] += dp_sum[i - 1] + dp[i];
    dp_sum[i] %= MOD;
  }

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


#include <iostream>
#include <vector>

using namespace std;
using ll = long long;

ll mod = 998244353;

int main() {
  int n, k;
  cin >> n >> k;

  vector<pair<ll, ll>> lr(k);
  for (auto &v : lr) {
    ll l, r;
    cin >> l >> r;
    v = make_pair(l, r);
  }

  vector<ll> vec1(3e5, 0), vec2(3e5, 0), vec3(3e5, 0);
  vec1[1] = 1;
  vec2[1] = 1;
  vec3[1] = 1;

  for (ll i = 1; i < n; ++i) {
    for (auto &v : lr) {
      ll l = v.first;
      ll r = v.second;
      vec1[i + l] = (vec1[i + l] + vec3[i]) % mod;
      vec2[i + r] = (vec2[i + r] + vec3[i]) % mod;
    }
    vec3[i + 1] = (vec3[i] - vec2[i]) % mod;
    if (vec3[i + 1] < 0)
      vec3[i + 1] += mod;
    vec3[i + 1] = (vec3[i + 1] + vec1[i + 1]) % mod;
  }

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

#include <iostream>
#include <vector>

using namespace std;
using ll = long long;

ll mod = 998244353;

int main() {
  int n, k;
  cin >> n >> k;

  vector<pair<ll, ll>> lr(k);
  for (auto &v : lr) {
    ll l, r;
    cin >> l >> r;
    v = make_pair(l, r);
  }

  vector<ll> vec1(5e5, 0), vec2(5e5, 0), vec3(5e5, 0);
  vec1[1] = 1;
  vec2[1] = 1;
  vec3[1] = 1;

  for (ll i = 1; i < n; ++i) {
    for (auto &v : lr) {
      ll l = v.first;
      ll r = v.second;
      vec1[i + l] = (vec1[i + l] + vec3[i]) % mod;
      vec2[i + r] = (vec2[i + r] + vec3[i]) % mod;
    }
    vec3[i + 1] = (vec3[i] - vec2[i]) % mod;
    if (vec3[i + 1] < 0)
      vec3[i + 1] += mod;
    vec3[i + 1] = (vec3[i + 1] + vec1[i + 1]) % mod;
  }

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


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

const ll dv = 998244353;

int main() {
  ll n, k;
  cin >> n >> k;
  vector<P> v(k);
  rep(i, k) { cin >> v.at(i).first >> v.at(i).second; }
  sort(v.begin(), v.end());

  vector<ll> dp(n + 1);
  dp.at(1) = 1;
  for (ll i = 2; i <= n; ++i) {
    rep(j, k) {
      for (ll t = v.at(j).first; t <= v.at(j).second; ++t) {
        if ((i - t) < 1) {
          j = k;
          break;
        }
        dp.at(i) += dp.at(i - t);
        dp.at(i) %= dv;
      }
    }
  }
  cout << dp.at(n) << endl;

  return 0;
}

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

const ll mod = 998244353;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a) {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a) {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(ll t) const {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint &operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream &operator>>(istream &is, mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }

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

  cout << dp.at(n) << endl;

  return 0;
}


#include <iostream>

typedef long long ll;

const ll MOD = 998244353;

ll N, K, dp[200005];
int S[11][3];

ll solve(int i) {
  if (i > N)
    return 0;
  if (i == N)
    return 1;
  if (dp[i] != -1)
    return dp[i];
  ll ans = 0;
  for (int k = 0; k < K; ++k)
    for (int d = S[k][0]; d <= S[k][1]; ++d)
      ans = (ans + solve(i + d)) % MOD;
  return dp[i] = ans;
}

int main() {
  std::cin >> N >> K;
  for (int i = 0; i < K; ++i)
    std::cin >> S[i][0] >> S[i][1];

  for (int i = 0; i < 200005; ++i)
    dp[i] = -1;

  std::cout << solve(1) << "\\n";

  return 0;
}

#include <iostream>

typedef long long ll;

const ll MOD = 998244353;

ll N, K, dp[200005], dps[200005];
int S[11][3];

ll sum(ll l, ll r) {
  if (r < 1)
    return 0;
  ll ans = dps[r];
  if (l > 1)
    ans = (ans - dps[l - 1] + MOD) % MOD;
  return ans;
}

int main() {
  std::cin >> N >> K;
  for (int i = 0; i < K; ++i)
    std::cin >> S[i][0] >> S[i][1];

  dps[0] = 0;
  dp[1] = 1, dps[1] = 1;
  for (int i = 2; i <= N; ++i) {
    dp[i] = 0;
    for (int k = 0; k < K; ++k)
      dp[i] = (dp[i] + sum(i - S[k][1], i - S[k][0])) % MOD;
    dps[i] = (dp[i] + dps[i - 1]) % MOD;
  }

  std::cout << dp[N] << "\\n";

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for (int i = a; i < b; i++)
#define each(i, mp) for (auto &i : mp)

const int INF = 1001001001;
const int takahashi = 998244353;
const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}

  mint operator-() const { return mint(-x); }

  mint &operator+=(const mint a) {
    if ((x += a.x) >= mod) {
      x -= mod;
    }

    return *this;
  }

  mint &operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) {
      x -= mod;
    }

    return *this;
  }

  mint &operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }

  mint operator+(const mint a) const { return mint(*this) += a; }

  mint operator-(const mint a) const { return mint(*this) -= a; }

  mint operator*(const mint a) const { return mint(*this) *= a; }

  mint pow(ll t) const {
    if (!t) {
      return 1;
    }
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) {
      a *= *this;
    }

    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }

  mint &operator/=(const mint a) { return *this *= a.inv(); }

  mint operator/(const mint a) const { return mint(*this) /= a; }
};

istream &operator>>(istream &is, mint &a) { return is >> a.x; }

ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }

ll ans = 0;
int n, k;
ll minus_counter(ll n, ll tmp) {
  ll counter = 0;
  while (1) {
    n -= tmp;
    if (n < 0) {
      return counter;
    } else {
      counter++;
    }
  }
}

int main() {
  cin >> n >> k;
  vector<int> l(k);
  vector<int> r(k);
  rep(i, k) {
    cin >> l[i];
    cin >> r[i];
  }
  vector<int> s;
  rep(i, k) {
    repr(j, l[i], r[i] + 1) { s.push_back(j); }
    if (l[i] == r[i]) {
      s.push_back(l[i]);
    }
  }
  sort(s.begin(), s.end());
  s.erase(std::unique(s.begin(), s.end()), s.end());
  // vector <ll> save_counter;
  // rep(i, s.size()) {
  //   save_counter.push_back(minus_counter(n, s[i]));
  // }
  vector<mint> dp(n + 1);
  dp[1] = 1;
  repr(i, 1, n) {
    // dp[i] %= takahashi;
    rep(j, s.size()) {
      if (i + j < n) {
        dp[i + s[j]] += dp[i];
      }
      // std::cout << "s = " << s[i] << '\\n';
    }
    // std::cout << "dp" << dp[i] << '\\n';
  }

  cout << dp[n] << endl;

  return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for (int i = a; i < b; i++)
#define each(i, mp) for (auto &i : mp)

const int INF = 1001001001;
const int takahashi = 998244353;
const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}

  mint operator-() const { return mint(-x); }

  mint &operator+=(const mint a) {
    if ((x += a.x) >= mod) {
      x -= mod;
    }

    return *this;
  }

  mint &operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) {
      x -= mod;
    }

    return *this;
  }

  mint &operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }

  mint operator+(const mint a) const { return mint(*this) += a; }

  mint operator-(const mint a) const { return mint(*this) -= a; }

  mint operator*(const mint a) const { return mint(*this) *= a; }

  mint pow(ll t) const {
    if (!t) {
      return 1;
    }
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) {
      a *= *this;
    }

    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }

  mint &operator/=(const mint a) { return *this *= a.inv(); }

  mint operator/(const mint a) const { return mint(*this) /= a; }
};

istream &operator>>(istream &is, mint &a) { return is >> a.x; }

ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }

ll ans = 0;
int n, k;
ll minus_counter(ll n, ll tmp) {
  ll counter = 0;
  while (1) {
    n -= tmp;
    if (n < 0) {
      return counter;
    } else {
      counter++;
    }
  }
}

int main() {
  cin >> n >> k;
  vector<int> l(k);
  vector<int> r(k);
  rep(i, k) {
    cin >> l[i];
    cin >> r[i];
  }
  // vector <int> s;
  // rep(i, k) {
  //   repr(j, l[i], r[i] + 1) {
  //     s.push_back(j);
  //   }
  //   if (l[i] == r[i]) { s.push_back(l[i]); }
  // }
  // sort(s.begin(), s.end());
  // s.erase(std::unique(s.begin(), s.end()), s.end());
  // vector <ll> save_counter;
  // rep(i, s.size()) {
  //   save_counter.push_back(minus_counter(n, s[i]));
  // }
  vector<mint> dp(n + 1);
  vector<mint> dpsum(n + 1);
  dp[1] = 1;
  dpsum[1] = 1;
  for (int i = 2; i <= n; ++i) {
    rep(j, k) {
      // [l[i], r[i]]
      int li = i - r[j];
      int ri = i - l[j];
      if (ri < 0) {
        continue;
      }
      li = max(li, 1);
      dp[i] += dpsum[ri] - dpsum[li - 1]; // dp[li]~dp[ri];
    }
    dpsum[i] = dpsum[i - 1] + dp[i];
  }
  cout << dp[n] << endl;

  return 0;
}


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

int main() {
  ll mod = 998244353;
  int n, k;
  set<int> vals;
  cin >> n >> k;
  for (int i = 0; i < k; i++) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++)
      vals.insert(j);
  }
  ll ways[n + 1];
  memset(ways, 0, sizeof(ways));
  ways[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (auto x : vals) {
      if (x >= i)
        break;
      ways[i] = (ways[i] + ways[i - x]) % mod;
    }
  }
  cout << ways[n] << "\\n";
}

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

int main() {
  ll mod = 998244353;
  int n, k;
  // set<int>vals;
  cin >> n >> k;
  pair<int, int> range[k];
  for (int i = 0; i < k; i++) {
    int l, r;
    cin >> l >> r;
    range[i] = {l, r};
    /*for(int i=l;i<=r;i++)
            vals.insert(i);*/
  }
  sort(range, range + k);
  ll ways[n + 1];
  memset(ways, 0, sizeof(ways));
  ways[1] = 1;
  ways[2] = -1;
  for (int i = 1; i <= n; i++) {
    if (i > 1)
      ways[i] = (ways[i - 1] + ways[i]) % mod;
    for (int j = 0; j < k; j++) {
      if (range[j].first + i > n)
        continue;
      ways[i + range[j].first] = (ways[i] + ways[i + range[j].first]) % mod;

      if (range[j].second + i + 1 > n)
        continue;
      ways[i + range[j].second + 1] =
          (ways[i + range[j].second + 1] - ways[i]) % mod;
    }
    //	ways[i] += ways[i-1];
  }
  /*for(int i=2;i<=n;i++)
  {
          for(int j=0;j<k;j++)
                  ways[i] = ways[i]+ways[i-1];
  }*/
  if (ways[n] < 0)
    ways[n] = mod + ways[n];
  cout << ways[n] << "\\n";
}


#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define sz(x) int(x.size())
#define bitsz(x) int(__builtin_popcount(x))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb(x) push_back(x)
#define INF 1e9
#define LINF 1e18
#define mod 1000000007
template <class T> inline bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T> inline string toString(const T &a) {
  ostringstream oss;
  oss << a;
  return oss.str();
};
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
const int di[4] = {1, 0, -1, 0};
const int dj[4] = {0, 1, 0, -1};

const int MOD = 998244353;

int main() {
  int n, k;
  cin >> n >> k;
  // vector<int> s;
  set<ll> s;
  rep(i, k) {
    int l, r;
    cin >> l >> r;
    for (int i = l; i <= r; i++) {
      // s.push_back(i);
      s.insert(i);
    }
  }

  ll dp[200005];
  dp[1] = 1;
  // rep(i,200005) {
  //     dp[i] = 0;
  // }

  priority_queue<ll, vector<ll>, greater<ll>> q;
  q.push(1);

  while (!q.empty()) {
    ll p = q.top();
    q.pop();
    for (auto x : s) {
      if (p + x > n)
        break;
      // if (dp[p+x] != 0) continue;
      if (dp[p + x] == 0)
        q.push(p + x);
      dp[p + x] += dp[p];
      dp[p + x] %= MOD;
    }
  }

  dp[n] = 0;
  for (auto x : s) {
    dp[n] += dp[n - x];
    dp[n] %= MOD;
  }

  // rep(i,n) {
  //     if (i!=0 && dp[i]==0) continue;
  //     for (auto x : s) {
  //         dp[i+x] = dp[i]+1;
  //     }
  //     // if (s.find(i)!=s.end()) { //集合にiがあるなら

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

#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define sz(x) int(x.size())
#define bitsz(x) int(__builtin_popcount(x))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb(x) push_back(x)
#define INF 1e9
#define LINF 1e18
// #define mod 1000000007
template <class T> inline bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T> inline string toString(const T &a) {
  ostringstream oss;
  oss << a;
  return oss.str();
};
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
const int di[4] = {1, 0, -1, 0};
const int dj[4] = {0, 1, 0, -1};

const int mod = 998244353;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a) {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a) {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(ll t) const {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint &operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream &operator>>(istream &is, mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }

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


#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> s;
  for (int i = 0; i < K; i++) {
    int li, ri;
    cin >> li >> ri;
    for (int j = li; j <= ri; j++) {
      s.emplace_back(j);
    }
  }
  int slen = s.size();

  vector<int> routnum(N, 0);
  routnum[0] = 1;
  for (int i = 1; i < N; i++) {
    for (int j = 0; j < slen; j++) {
      if (i - s[j] >= 0) {
        routnum[i] += routnum[i - s[j]];
        routnum[i] %= mod;
      }
    }
  }

  cout << routnum[N - 1] << endl;
}

#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;

// いもす法を使ったDP(本番終了後の実装)
int main() {
  int N, K;
  cin >> N >> K;
  vector<pair<int, int>> s;
  for (int i = 0; i < K; i++) {
    int li, ri;
    cin >> li >> ri;
    pair<int, int> si(li, ri);
    s.emplace_back(si);
  }
  int slen = s.size();

  vector<int> routnum(N, 0);
  vector<int> routnumdif(N - 1, 0); // -> routnum[i+1]-routnum[i]
  routnum[0] = 1;
  routnumdif[0] = -1;
  for (int i = 0; i < N - 1; i++) {
    for (int j = 0; j < K; j++) {
      int lj = s[j].first;
      int rj = s[j].second;
      if (i + lj - 1 < N - 1) {
        routnumdif[i + lj - 1] += routnum[i];
        routnumdif[i + lj - 1] %= mod;
      }
      if (i + rj < N - 1) {
        routnumdif[i + rj] -= routnum[i];
        routnumdif[i + rj] += mod;
        routnumdif[i + rj] %= mod;
      }
    }
    routnum[i + 1] = routnum[i] + routnumdif[i];
    routnum[i + 1] %= mod;
  }

  cout << routnum[N - 1] << endl;
}


#include <algorithm>
#include <bits/stdc++.h>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <set>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
long long int n, k;
vector<long long int> all;
vector<long long int> dp;
int main(void) {
  cin >> n >> k;
  vector<pair<long long int, long long int>> hoge(n);
  for (long long int i = 0; i < k; i++) {
    cin >> hoge.at(i).first >> hoge.at(i).second;
    for (long long int j = hoge.at(i).first; j <= hoge.at(i).second; j++) {
      all.push_back(j);
    }
  }
  sort(all.begin(), all.end());
  dp = vector<long long int>(n, 0);
  dp.at(0) = 1;
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < all.size(); j++) {
      long long int next = i + all.at(j);
      if (next >= n) {
        break;
      }
      dp.at(next) += dp.at(i);
      dp.at(next) %= 998244353;
    }
  }
  dp.at(n - 1) %= 998244353;
  cout << dp.at(n - 1) << endl;
}

#include <algorithm>
#include <bits/stdc++.h>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <set>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
int main(void) {
  long long int mod = 998244353;
  long long int n;
  cin >> n;
  long long int k;
  cin >> k;
  vector<pair<long long int, long long int>> hoge(k);
  for (long long int i = 0; i < k; i++) {
    cin >> hoge.at(i).first >> hoge.at(i).second;
  }
  vector<long long int> dp(n, 0);
  vector<long long int> rui(n, 0);
  rui.at(0) = 0;
  dp.at(0) = 1;
  vector<long long int> imos(n, 0);
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < k; j++) {
      if (i + hoge.at(j).first < n)
        imos.at(i + hoge.at(j).first) += dp.at(i);
      if (i + hoge.at(j).second + 1 < n)
        imos.at(i + hoge.at(j).second + 1) -= dp.at(i);
      if (i != n - 1) {
        rui.at(i + 1) %= mod;
        rui.at(i + 1) = rui.at(i) + imos.at(i + 1);
        dp.at(i + 1) = rui.at(i + 1);
        dp.at(i + 1) %= mod;
      }
    }
  }
  cout << dp.at(n - 1) << endl;
}


/*
Dont BLUNDER
*/

// #pragma GCC optimize("O3")
// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimization ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

 */
// #define d long double
#define int long long
#define pii pair<int, int>
#define pb push_back
#define endl '\\n'
#define pi acos(-1)

#define init(x, a) memset(x, a, sizeof(x))
#define all(c) c.begin(), c.end()
int const mod1 = 998244353;
int const mod = 1000000007;
#define bitcount(x) __builtin_popcountll(x)
#define l first
#define r second
const int inf = LLONG_MAX;
int toint(const string &s) {
  stringstream ss;
  ss << s;
  int x;
  ss >> x;
  return x;
}
string tostring(int number) {
  stringstream ss;
  ss << number;
  return ss.str();
}
#define trace1(x) cerr << #x << ": " << x << endl
#define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl
#define trace3(x, y, z)                                                        \\
  cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": "    \\
       << z << endl
#define haha                                                                   \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
// * Using PBDS *
/*typedef tree<int, null_type, less<int>, rb_tree_tag,
            tree_order_statistics_node_update>
               os; */

struct cmp {
  bool operator()(pii a, pii b) { return (a.l < b.l); }
};

int modexp(int x, int n) {
  if (n == 0) {
    return 1;
  } else if (n & 1) {
    return (modexp((x * x) % mod, n / 2) % mod * x % mod) % mod;
  } else {
    return (modexp((x * x) % mod, n / 2) % mod);
  }
}

int modinv(int n) { return modexp(n, mod - 2); }

int gcd(int a, int b) {
  if (b == 0) {
    return a;
  }
  return gcd(b, a % b);
}

int segm_tree[400001];
int a[200001];

void recalculate(int node) {
  // calculate the solution for the current segment,
  // considering the sons are correctly solved
  segm_tree[node] = (segm_tree[2 * node] + segm_tree[2 * node + 1]) % mod1;
}

void build(int node, int left,
           int right) { //"node" is the index in the array, while "left"
  // and "right" are the ends of the current segment
  if (left == right) {
    segm_tree[node] = a[left]; // we are in a leaf node
  } else {
    int middle = (left + right) / 2;
    build(2 * node, left, middle);
    build(2 * node + 1, middle + 1, right);
    recalculate(node);
  }
}

void update(int node, int left, int right, int x, int y) {
  if (left == right) { // we are in the xth leaf
    segm_tree[node] = y;
  } else {
    int middle = (left + right) / 2;
    if (x <= middle) { // we need to update the left son
      update(2 * node, left, middle, x, y);
    } else {
      update(2 * node + 1, middle + 1, right, x, y);
    }
    // after updating said son, recalculate the current segment
    recalculate(node);
  }
}

int query(int node, int left, int right, int x, int y) {

  if (y < left or right < x) {
    // range represented by a node is completely outside the given range
    return 0;
  }
  if (x <= left && right <= y) {
    // the segment of "node" is completely included in the query
    return segm_tree[node];
  } else {
    // int answer = -10000;
    int middle = (left + right) / 2;
    int p1 = query(2 * node, left, middle, x, y);
    int p2 = query(2 * node + 1, middle + 1, right, x, y);
    // we would not have entered this function if (x, y) and (left, right) had
    // nothing in common, so there is no risk of answer returning -Infinity
    // here, as either the left or the right son would update it
    return (p1 + p2) % mod1;
  }
}

signed main() {
  haha
#ifndef ONLINE_JUDGE

      freopen("inp.txt", "r", stdin);

  freopen("out1.txt", "w", stdout);
#endif
  vector<pii> v;
  int n, k;
  cin >> n >> k;
  int ans = 0;

  init(a, 0);

  a[1] = 1;
  build(1, 1, n);
  for (int i = 0; i < k; i++) {
    int x;
    int y;
    cin >> x >> y;
    v.pb({x, y});
  }
  for (int i = 2; i <= n; i++) {
    int temp = 0;
    for (auto x : v) {
      int l = x.first;
      int r = x.second;
      if (i - l >= 1) {
        int qr = i - l;
        int ql = max(1ll, i - r);
        temp += query(1, 1, n, ql, qr);
        temp %= mod1;
      }
    }
    a[i] = temp;
    update(1, 1, n, i, temp);
  }

  cout << a[n];
}

/*
Dont BLUNDER
*/

// #pragma GCC optimize("O3")
// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimization ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

 */
// #define d long double
#define int long long
#define pii pair<int, int>
#define pb push_back
#define endl '\\n'
#define pi acos(-1)

#define init(x, a) memset(x, a, sizeof(x))
#define all(c) c.begin(), c.end()
int const mod1 = 998244353;
int const mod = 1000000007;
#define bitcount(x) __builtin_popcountll(x)
#define l first
#define r second
const int inf = LLONG_MAX;
int toint(const string &s) {
  stringstream ss;
  ss << s;
  int x;
  ss >> x;
  return x;
}
string tostring(int number) {
  stringstream ss;
  ss << number;
  return ss.str();
}
#define trace1(x) cerr << #x << ": " << x << endl
#define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl
#define trace3(x, y, z)                                                        \\
  cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": "    \\
       << z << endl
#define haha                                                                   \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
// * Using PBDS *
/*typedef tree<int, null_type, less<int>, rb_tree_tag,
            tree_order_statistics_node_update>
               os; */

struct cmp {
  bool operator()(pii a, pii b) { return (a.l < b.l); }
};

int modexp(int x, int n) {
  if (n == 0) {
    return 1;
  } else if (n & 1) {
    return (modexp((x * x) % mod, n / 2) % mod * x % mod) % mod;
  } else {
    return (modexp((x * x) % mod, n / 2) % mod);
  }
}

int modinv(int n) { return modexp(n, mod - 2); }

int gcd(int a, int b) {
  if (b == 0) {
    return a;
  }
  return gcd(b, a % b);
}

int segm_tree[600001];
int a[200001];

void recalculate(int node) {
  // calculate the solution for the current segment,
  // considering the sons are correctly solved
  segm_tree[node] = (segm_tree[2 * node] + segm_tree[2 * node + 1]) % mod1;
}

void build(int node, int left,
           int right) { //"node" is the index in the array, while "left"
  // and "right" are the ends of the current segment
  if (left == right) {
    segm_tree[node] = a[left]; // we are in a leaf node
  } else {
    int middle = (left + right) / 2;
    build(2 * node, left, middle);
    build(2 * node + 1, middle + 1, right);
    recalculate(node);
  }
}

void update(int node, int left, int right, int x, int y) {
  if (left == right) { // we are in the xth leaf
    segm_tree[node] = y;
  } else {
    int middle = (left + right) / 2;
    if (x <= middle) { // we need to update the left son
      update(2 * node, left, middle, x, y);
    } else {
      update(2 * node + 1, middle + 1, right, x, y);
    }
    // after updating said son, recalculate the current segment
    recalculate(node);
  }
}

int query(int node, int left, int right, int x, int y) {

  if (y < left or right < x) {
    // range represented by a node is completely outside the given range
    return 0;
  }
  if (x <= left && right <= y) {
    // the segment of "node" is completely included in the query
    return segm_tree[node];
  } else {
    // int answer = -10000;
    int middle = (left + right) / 2;
    int p1 = query(2 * node, left, middle, x, y);
    int p2 = query(2 * node + 1, middle + 1, right, x, y);
    // we would not have entered this function if (x, y) and (left, right) had
    // nothing in common, so there is no risk of answer returning -Infinity
    // here, as either the left or the right son would update it
    return (p1 + p2) % mod1;
  }
}

signed main() {
  haha
#ifndef ONLINE_JUDGE

      freopen("inp.txt", "r", stdin);

  freopen("out1.txt", "w", stdout);
#endif
  vector<pii> v;
  int n, k;
  cin >> n >> k;
  int ans = 0;

  init(a, 0);

  a[1] = 1;
  build(1, 1, n);
  for (int i = 0; i < k; i++) {
    int x;
    int y;
    cin >> x >> y;
    v.pb({x, y});
  }
  for (int i = 2; i <= n; i++) {
    int temp = 0;
    for (auto x : v) {
      int l = x.first;
      int r = x.second;
      if (i - l >= 1) {
        int qr = i - l;
        int ql = max(1ll, i - r);
        temp += query(1, 1, n, ql, qr);
        temp %= mod1;
      }
    }
    a[i] = temp;
    update(1, 1, n, i, temp);
  }

  cout << a[n];
}


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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> s;
  long long MOD = 998244353;

  for (int i = 0; i < k; i++) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j < r + 1; j++) {
      s.push_back(j);
    }
  }

  // sを用いてiにたどり着くまでの方法
  vector<long long> dp(n + 1, 0);
  dp[1] = 1;
  for (int i = 2; i < n + 1; i++) {
    for (int mid : s) {
      if (i > mid)
        dp[i] = (dp[i] + dp[i - mid]) % MOD;
    }
  }

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

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<pair<int, int>> s;
  long long MOD = 998244353;

  for (int i = 0; i < k; i++) {
    int l, r;
    cin >> l >> r;
    s.push_back(make_pair(l, r));
  }

  // sを用いてiにたどり着くまでの方法
  vector<long long> dp(n + 1, 0);
  // 累積和
  vector<long long> cuml(n + 1, 0);
  dp[1] = 1;
  cuml[1] = 1;

  for (int i = 2; i < n + 1; i++) {
    for (int j = 0; j < k; j++) {
      int l, r;
      if (i - s[j].first < 1)
        continue;
      r = i - s[j].first;
      l = max(1, i - s[j].second);

      dp[i] = (dp[i] + cuml[r] - cuml[l - 1] + MOD) % MOD;
    }
    // 累積和を更新する
    cuml[i] = (cuml[i - 1] + dp[i]) % MOD;
  }

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


#include <algorithm>
#include <cstdio>
#include <iostream>
#define maxn 200005
#define mod 998244353
using namespace std;
int n, k, cnt;
int step[maxn];
long long ans;
long long dp[maxn];
int main() {
  cin >> n >> k;
  for (int i = 1; i <= k; i++) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++)
      step[++cnt] = j;
  }
  sort(step + 1, step + 1 + cnt);
  dp[1] = 1ll;
  for (int i = 2; i <= n; i++) {
    for (int j = 1; j <= cnt; j++)
      if (i - step[j] >= 0) {
        if (dp[i - step[j]])
          (dp[i] += dp[i - step[j]]) %= mod;
      } else
        break;
  }

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

#include <algorithm>
#include <cstdio>
#include <iostream>
#define maxn 200005
#define mod 998244353
using namespace std;
int n, k, cnt;
long long A;
int l[maxn], r[maxn];
long long tree[maxn];

int lowbit(int x) { return x & (-x); }
void add(int x, long long v) {
  for (; x <= n; x += lowbit(x))
    (tree[x] += v) %= mod;
}
long long getsum(int x) {
  A = 0;
  for (; x >= 1; x -= lowbit(x))
    (A += tree[x]) %= mod;
  return A % mod;
}

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

  add(1, 1);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= k; j++)
      if (i > l[j]) {
        add(i, (getsum(i - l[j]) - getsum(max(0, i - r[j] - 1)) + mod) % mod);
        //		cout<<i-l[i]<<" "<<i-r[i]-1<<endl;
        //		cout<<i<<" "<<getsum(i-l[i])<<"
        //"<<getsum(max(0,i-r[i]-1))<<endl;
      }
  //	for(int i=1;i<=n;i++) cout<<getsum(i)-getsum(i-1)<<" ";
  //	cout<<endl;
  cout << (getsum(n) % mod - getsum(n - 1) % mod + mod) % mod << endl;
}


#include <bits/stdc++.h>
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repi(i, 0, n)
#define SZ(x) ((int)(x).size())
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
// using P = pair<int, int>;
struct Vec {
  double x, y;
};
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;
}
using namespace std;

int dp[200008];
// int s[20008];
const int mod = 998244353;

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  // cout << fixed << setprecision(15);

  int n, k, p = 0;
  cin >> n >> k;

  vector<int> s;

  rep(i, k) {
    int l, r;
    cin >> l >> r;
    repi(m, l, r + 1) { s.push_back(m); }
  }

  rep(i, n) dp[i] = 0;

  dp[1] = 1;
  repi(i, 2, n + 1) {
    for (auto &l : s) {
      if ((i - l) <= 0)
        continue;
      dp[i] += dp[i - l];
      dp[i] %= mod;
    }
  }
  cout << dp[n] << endl;

  return 0;
}

#include <bits/stdc++.h>
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repi(i, 0, n)
#define SZ(x) ((int)(x).size())
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
// using P = pair<int, int>;
struct Vec {
  double x, y;
};
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;
}
using namespace std;

const int mod = 998244353;
// const int mod = 1000000007;
class mint {
public:
  ll x;
  mint(ll x = 0) : x((x % mod + mod) % 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 a) const {
    if (a == 0)
      return 1;
    mint b = pow(a >> 1);
    b *= b;
    if (a & 1)
      b *= (*this);
    return b;
  }
  mint inv() const { return pow(mod - 2); }
  mint &operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
  friend ostream &operator<<(ostream &os, const mint &m) {
    os << m.x;
    return os;
  }
};

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  // cout << fixed << setprecision(15);

  // DPを使ってTLE
  int n, k;
  cin >> n >> k;

  vector<pair<int, int>> s;

  rep(i, k) {
    int l, r;
    cin >> l >> r;
    s.push_back(pair<int, int>(l, r));
  }

  vector<mint> imo(n + 1, 0);
  vector<mint> dp(n + 1, 0);

  dp[1] = 1;
  imo[1] = 1;
  repi(i, 2, n + 1) {
    for (auto &m : s) {
      int l, r;
      l = max(i - m.second, 1);
      r = i - m.first;
      if (r < 0)
        continue;
      dp[i] += imo[r] - imo[l - 1];
    }
    imo[i] += dp[i] + imo[i - 1];
  }
  cout << dp[n] << endl;

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define rep(i, a, b, c) for (ll i = (a); i <= (b); i += (c))
#define repb(i, a, b, c) for (ll i = (a); i >= (b); i -= (c))
#define MOD 998244353
#define inf 3e18
#define ld long double
#define mp make_pair
#define vpll vector<pair<ll, ll>>
#define vll vector<ll>
#define vld vector<ld>
#define vvll vector<vector<ll>>
#define vvld vector<vector<ld>>
#define pll pair<ll, ll>
#define vvpll vector<vector<pair<ll, ll>>>
#define pqll priority_queue<ll>
#define mll map<ll, ll>
#define mlc map<ll, char>
#define um unordered_map
#define umll um<ll, ll>
#define umlc um<ll, char>
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define ln cout << "\\n";
#define endl "\\n"
#define test                                                                   \\
  ll T;                                                                        \\
  cin >> T;                                                                    \\
  while (T--)
#define isvowel(a) (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
#define fastIO                                                                 \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define show(w, size)                                                          \\
  for (ll i = 0; i < size; i++)                                                \\
    cout << w[i] << " ";
#define prll(a) cout << a << "\\n";
#define mset(dp, no) memset(dp, no, sizeof(dp))
#define input(a, n) rep(i, 0, n - 1, 1) cin >> a[i];
#define countbit __builtin_popcount // Number of setbits in decimal notation
#define lb(v, cur) lower_bound(all(v), cur) - v.begin()
#define ub(v, cur) upper_bound(all(v), cur) - v.begin()
#define db(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
  cerr << name << " : " << arg1 << '\\n';
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
  const char *comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
long long pows(long long a, long long b) {
  long long res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a;
    a = a * a;
    b >>= 1;
  }
  return res;
}
ll powm(ll x, ll y, ll m = MOD) {
  x = x % m;
  ll res = 1;
  while (y) {
    if (y & 1)
      res = res * x;
    res %= m;
    y = y >> 1;
    x = x * x;
    x %= m;
  }
  return res;
}
ll modInverse(ll a, ll m = MOD) { return powm(a, m - 2, m); }
ll ar[200005];
int main() {
  fastIO ll n, m, i, j, k, x, y, z, t, e, f, p, q, g, l, r, o, w, h,
      count1 = 0, prod = 1, a, b, c, d, index, x1, x2, y1, y2, diff, ans = 0,
      sum = 0, sum1 = 0, sum2 = 0, flag = 0, flag1 = 0, flag2 = 0;
  string s, s1, s2;
  cin >> n >> k;
  vll v;
  mll m1;
  for (i = 0; i < k; i++) {
    cin >> a >> b;
    for (j = a; j <= b; j++) {
      m1[j]++;
    }
  }
  for (auto i : m1) {
    v.pb(i.fi);
  }
  ar[1] = 1;
  for (i = 1; i <= n; i++) {
    for (j = 0; j < v.size(); j++) {
      if (i + v[j] <= n) {
        ar[i + v[j]] += ar[i];
        ar[i + v[j]] %= MOD;
      } else {
        break;
      }
    }
  }
  cout << ar[n];
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define rep(i, a, b, c) for (ll i = (a); i <= (b); i += (c))
#define repb(i, a, b, c) for (ll i = (a); i >= (b); i -= (c))
#define MOD 998244353
#define inf 3e18
#define ld long double
#define mp make_pair
#define vpll vector<pair<ll, ll>>
#define vll vector<ll>
#define vld vector<ld>
#define vvll vector<vector<ll>>
#define vvld vector<vector<ld>>
#define pll pair<ll, ll>
#define vvpll vector<vector<pair<ll, ll>>>
#define pqll priority_queue<ll>
#define mll map<ll, ll>
#define mlc map<ll, char>
#define um unordered_map
#define umll um<ll, ll>
#define umlc um<ll, char>
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define ln cout << "\\n";
#define endl "\\n"
#define test                                                                   \\
  ll T;                                                                        \\
  cin >> T;                                                                    \\
  while (T--)
#define isvowel(a) (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
#define fastIO                                                                 \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define show(w, size)                                                          \\
  for (ll i = 0; i < size; i++)                                                \\
    cout << w[i] << " ";
#define prll(a) cout << a << "\\n";
#define mset(dp, no) memset(dp, no, sizeof(dp))
#define input(a, n) rep(i, 0, n - 1, 1) cin >> a[i];
#define countbit __builtin_popcount // Number of setbits in decimal notation
#define lb(v, cur) lower_bound(all(v), cur) - v.begin()
#define ub(v, cur) upper_bound(all(v), cur) - v.begin()
#define db(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
  cerr << name << " : " << arg1 << '\\n';
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
  const char *comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
long long pows(long long a, long long b) {
  long long res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a;
    a = a * a;
    b >>= 1;
  }
  return res;
}
ll powm(ll x, ll y, ll m = MOD) {
  x = x % m;
  ll res = 1;
  while (y) {
    if (y & 1)
      res = res * x;
    res %= m;
    y = y >> 1;
    x = x * x;
    x %= m;
  }
  return res;
}
ll modInverse(ll a, ll m = MOD) { return powm(a, m - 2, m); }
ll ar[200005];
int main() {
  fastIO ll n, m, i, j, k, x, y, z, t, e, f, p, q, g, l, r, o, w, h,
      count1 = 0, prod = 1, a, b, c, d, index, x1, x2, y1, y2, diff, ans = 0,
      sum = 0, sum1 = 0, sum2 = 0, flag = 0, flag1 = 0, flag2 = 0;
  string s, s1, s2;
  cin >> n >> k;
  mll m1;
  vpll v(n);
  for (i = 0; i < k; i++) {
    cin >> v[i].fi >> v[i].se;
  }
  ar[0] = 1;
  ar[1] = -1;
  for (i = 0; i < n; i++) {
    if (i > 0) {
      ar[i] += ar[i - 1];
      ar[i] %= MOD;
    }
    for (j = 0; j < k; j++) {
      a = v[j].fi;
      b = v[j].se + 1;
      if (i + b <= n) {
        ar[i + b] -= ar[i];
        ar[i + b] += MOD;
        ar[i + b] %= MOD;
      }
      if (i + a <= n) {
        ar[i + a] += ar[i];
        ar[i + a] %= MOD;
      }
    }
  }
  cout << ar[n - 1];
}


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

const int mod = 998244353;
int n, k;
vector<pair<int, int>> s;
vector<ll> dp;
ll path(int x, vector<ll> &dp) {
  ll res = 0;
  rep(i, k) {
    for (int j = s[i].first; j <= s[i].second; j++) {
      if (x - j >= 0) {
        if (dp[x - j] != -1)
          res = (res + dp[x - j]) % mod;
        else
          res = (res + path(x - j, dp)) % mod;
      }
    }
  }
  dp[x] = res;
  return res;
}

int main() {
  cin >> n >> k;
  s.resize(k);
  rep(i, k) { cin >> s[i].first >> s[i].second; }
  dp.assign(n, -1);
  dp[0] = 1;
  cout << path(n - 1, dp) << endl;
}

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

const int mod = 998244353;
struct mint {
  ll x;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a) {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a) {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<pair<int, int>> s(k);
  rep(i, k) { cin >> s[i].first >> s[i].second; }
  vector<mint> dp(n);
  vector<mint> sum(n);
  sum[0] = 1;
  dp[0] = 1;
  rep(i, n) {
    rep(j, k) {
      if (i - s[j].first >= 0)
        dp[i] += sum[i - s[j].first];
      if (i - s[j].second - 1 >= 0)
        dp[i] -= sum[i - s[j].second - 1];
    }
    if (i)
      sum[i] += dp[i] + sum[i - 1];
  }
  cout << dp[n - 1].x << endl;
}