#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000; // 1e18
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

/*  ----------------------- DEBUG FUNCTION ---------------------------- */
#define DUMPOUT cerr
void dump_function() { DUMPOUT << ' '; }
void dump_function(bool a) { DUMPOUT << a; }
void dump_function(int a) { DUMPOUT << a; }
void dump_function(long long a) { DUMPOUT << a; }
void dump_function(char a) { DUMPOUT << a; }
void dump_function(string &a) { DUMPOUT << a; }
void dump_function(double a) { DUMPOUT << a; }
template <class T> void dump_function(const vector<T> &);
template <class T, size_t size> void dump_function(const array<T, size> &);
template <class T, class L> void dump_function(const pair<T, L> &p);
template <class T, size_t size> void dump_function(const T (&)[size]);
template <class T> void dump_function(const vector<T> &a) {
  if (a.empty())
    return;
  dump_function(a[0]);
  for (auto i = a.begin(); ++i != a.end();) {
    DUMPOUT << " ";
    dump_function(*i);
  }
  DUMPOUT << endl;
}
template <class T> void dump_function(const deque<T> &a) {
  if (a.empty())
    return;
  dump_function(a[0]);
  for (auto i = a.begin(); ++i != a.end();) {
    DUMPOUT << " ";
    dump_function(*i);
  }
}
template <class T, size_t size> void dump_function(const array<T, size> &a) {
  dump_function(a[0]);
  for (auto i = a.begin(); ++i != a.end();) {
    DUMPOUT << " ";
    dump_function(*i);
  }
}
template <class T, class L> void dump_function(const pair<T, L> &p) {
  DUMPOUT << '(';
  dump_function(p.first);
  DUMPOUT << ",";
  dump_function(p.second);
  DUMPOUT << ')';
}
template <class T> void dump_function(set<T> &x) {
  for (auto e : x)
    dump_function(e), DUMPOUT << " ";
  DUMPOUT << endl;
}
template <class T> void dump_function(multiset<T> &x) {
  for (auto e : x)
    dump_function(e), DUMPOUT << " ";
  DUMPOUT << endl;
}
template <class T, size_t size> void dump_function(const T (&a)[size]) {
  dump_function(a[0]);
  for (auto i = a; ++i != end(a);) {
    DUMPOUT << " ";
    dump_function(*i);
  }
}
template <class T> void dump_function(const T &a) { DUMPOUT << a; }
int dump_out() {
  DUMPOUT << '\\n';
  return 0;
}
template <class T> int dump_out(const T &t) {
  dump_function(t);
  DUMPOUT << '\\n';
  return 0;
}
template <class Head, class... Tail>
int dump_out(const Head &head, const Tail &...tail) {
  dump_function(head);
  DUMPOUT << ' ';
  dump_out(tail...);
  return 0;
}

#ifdef DEBUG_
#define dump(x)                                                                \\
  DUMPOUT << #x << ": ";                                                       \\
  dump_function(x);                                                            \\
  DUMPOUT << endl;
void dumps() {}
template <class T> void dumps(const T &t) {
  dump_function(t);
  DUMPOUT << " ";
}
template <class Head, class... Tail>
void dumps(const Head &head, const Tail &...tail) {
  dump_function(head);
  DUMPOUT << ' ';
  dump_out(tail...);
}
#else
#define dump(x)
template <class... T> void dumps(const T &...) {}
#endif
/*  ----------------------- DEBUG FUNCTION ---------------------------- */

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 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];
  }
  constexpr T perm(int n, int k) const noexcept {
    if (n < k || n < 0 || k < 0)
      return 0;
    return fact_[n] * finv_[n - k];
  }
};

using mint = Fp<MOD2>;
BiCoef<mint> bc;
// using vec = vector<mint>;
// using mat = vector<vec>;

/*  ----------------------- AtCoder Library ---------------------------- */
// #include <atcoder/all>
// using namespace atcoder;
/*  ----------------------- AtCoder Library ---------------------------- */

void solve() {
  int N, K;
  cin >> N >> K;
  vector<int> S;
  REP(i, K) {
    int L, R;
    cin >> L >> R;
    for (int i = L; i <= R; i++)
      S.emplace_back(i);
  }
  sort(S.begin(), S.end());
  vector<ll> dp(N + 10, -1);
  auto dfs = [&](auto &&self, int A) -> ll {
    if (A < 0)
      return 0;
    else if (A == 0)
      return 1;
    if (dp[A] >= 0)
      return dp[A];
    ll res = 0;
    for (auto x : S) {
      if (A - x < 0)
        break;
      res += self(self, A - x);
      res %= MOD2;
    }
    return dp[A] = res;
  };
  cout << dfs(dfs, N - 1) << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  // int T; cin >> T; REP(t,T) solve();
}

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000; // 1e18
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

/*  ----------------------- DEBUG FUNCTION ---------------------------- */
#define DUMPOUT cerr
void dump_function() { DUMPOUT << ' '; }
void dump_function(bool a) { DUMPOUT << a; }
void dump_function(int a) { DUMPOUT << a; }
void dump_function(long long a) { DUMPOUT << a; }
void dump_function(char a) { DUMPOUT << a; }
void dump_function(string &a) { DUMPOUT << a; }
void dump_function(double a) { DUMPOUT << a; }
template <class T> void dump_function(const vector<T> &);
template <class T, size_t size> void dump_function(const array<T, size> &);
template <class T, class L> void dump_function(const pair<T, L> &p);
template <class T, size_t size> void dump_function(const T (&)[size]);
template <class T> void dump_function(const vector<T> &a) {
  if (a.empty())
    return;
  dump_function(a[0]);
  for (auto i = a.begin(); ++i != a.end();) {
    DUMPOUT << " ";
    dump_function(*i);
  }
  DUMPOUT << endl;
}
template <class T> void dump_function(const deque<T> &a) {
  if (a.empty())
    return;
  dump_function(a[0]);
  for (auto i = a.begin(); ++i != a.end();) {
    DUMPOUT << " ";
    dump_function(*i);
  }
}
template <class T, size_t size> void dump_function(const array<T, size> &a) {
  dump_function(a[0]);
  for (auto i = a.begin(); ++i != a.end();) {
    DUMPOUT << " ";
    dump_function(*i);
  }
}
template <class T, class L> void dump_function(const pair<T, L> &p) {
  DUMPOUT << '(';
  dump_function(p.first);
  DUMPOUT << ",";
  dump_function(p.second);
  DUMPOUT << ')';
}
template <class T> void dump_function(set<T> &x) {
  for (auto e : x)
    dump_function(e), DUMPOUT << " ";
  DUMPOUT << endl;
}
template <class T> void dump_function(multiset<T> &x) {
  for (auto e : x)
    dump_function(e), DUMPOUT << " ";
  DUMPOUT << endl;
}
template <class T, size_t size> void dump_function(const T (&a)[size]) {
  dump_function(a[0]);
  for (auto i = a; ++i != end(a);) {
    DUMPOUT << " ";
    dump_function(*i);
  }
}
template <class T> void dump_function(const T &a) { DUMPOUT << a; }
int dump_out() {
  DUMPOUT << '\\n';
  return 0;
}
template <class T> int dump_out(const T &t) {
  dump_function(t);
  DUMPOUT << '\\n';
  return 0;
}
template <class Head, class... Tail>
int dump_out(const Head &head, const Tail &...tail) {
  dump_function(head);
  DUMPOUT << ' ';
  dump_out(tail...);
  return 0;
}

#ifdef DEBUG_
#define dump(x)                                                                \\
  DUMPOUT << #x << ": ";                                                       \\
  dump_function(x);                                                            \\
  DUMPOUT << endl;
void dumps() {}
template <class T> void dumps(const T &t) {
  dump_function(t);
  DUMPOUT << " ";
}
template <class Head, class... Tail>
void dumps(const Head &head, const Tail &...tail) {
  dump_function(head);
  DUMPOUT << ' ';
  dump_out(tail...);
}
#else
#define dump(x)
template <class... T> void dumps(const T &...) {}
#endif
/*  ----------------------- DEBUG FUNCTION ---------------------------- */

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 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];
  }
  constexpr T perm(int n, int k) const noexcept {
    if (n < k || n < 0 || k < 0)
      return 0;
    return fact_[n] * finv_[n - k];
  }
};

using mint = Fp<MOD2>;
BiCoef<mint> bc;
// using vec = vector<mint>;
// using mat = vector<vec>;

/*  ----------------------- AtCoder Library ---------------------------- */
// #include <atcoder/all>
// using namespace atcoder;
/*  ----------------------- AtCoder Library ---------------------------- */

void solve() {
  int N, K;
  cin >> N >> K;
  vector<int> L(N), R(N);
  REP(i, K) cin >> L[i] >> R[i];
  vector<mint> dp(N + 10), imos(N + 10);
  dp[0] = 1;
  REP(i, N) {
    if (i > 0)
      imos[i] += imos[i - 1];
    dp[i] += imos[i];
    REP(j, K) {
      int l = L[j] + i;
      int r = R[j] + i + 1;
      if (l < N)
        imos[l] += dp[i];
      if (r < N)
        imos[r] -= dp[i];
    }
  }
  cout << dp[N - 1] << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  // int T; cin >> T; REP(t,T) solve();
}


#include <bits/stdc++.h>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <vector>
using namespace std;
typedef long long LL;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) {
  if (a > b)
    a = b;
}
template <typename T1, typename T2> inline void chmax(T1 &a, T2 b) {
  if (a < b)
    a = b;
}

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> L(K), R(K);
  REP(i, K) { cin >> L[i] >> R[i]; }

  LL ans = 0;
  LL M = 998244353;

  vector<LL> route(N + 1, 0);
  route[1] = 1;

  for (int i = 2; i <= N; i++) {
    for (int k = 0; k < K; k++) {
      for (int j = L[k]; j <= R[k]; j++) {
        if (i - j < 0) {
          break;
        }
        route[i] = (route[i] + route[i - j]) % M;
        // cout << "i: " << i << ", val:" << route[i] << endl;
      }
    }
  }

  cout << route[N] << endl;
  return 0;
}

#include <bits/stdc++.h>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <vector>
using namespace std;
typedef long long LL;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) {
  if (a > b)
    a = b;
}
template <typename T1, typename T2> inline void chmax(T1 &a, T2 b) {
  if (a < b)
    a = b;
}

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> L(K), R(K);
  vector<LL> Sums(K, 0);
  REP(i, K) { cin >> L[i] >> R[i]; }

  LL ans = 0;
  LL M = 998244353;

  vector<LL> route(N + 1, 0);
  route[1] = 1;

  for (int i = 2; i <= N; i++) {

    for (int k = 0; k < K; k++) {

      if (i - L[k] < 0) {
        continue;
      }

      if (i - L[k] >= 0) {
        int index = i - R[k] - 1;
        if (index >= 0) {
          LL tmp = (Sums[k] - route[index]) % M;
          if (tmp < 0) {
            tmp += M;
          }
          Sums[k] = (route[i - L[k]] + tmp) % M;
        } else {
          Sums[k] = (Sums[k] + route[i - L[k]]) % M;
        }
      }
    }

    for (int k = 0; k < K; k++) {
      route[i] = (route[i] + Sums[k]) % M;
    }
  }

  cout << route[N] << endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, N) for (int i = 0; i < int(N); ++i)
using ll = long long;
const ll MOD = 998244353;
const int INF = 1001001001;
// const ll INF = 1000000000000000000LL;

int main() {
  ll n, k;
  cin >> n >> k;
  vector<pair<ll, ll>> pr(k);
  rep(i, k) {
    ll a, b;
    cin >> a >> b;
    pr[i].first = a;
    pr[i].second = b;
  }
  sort(pr.begin(), pr.end());

  vector<ll> dp(n);
  vector<ll> dp_sum(n + 1);
  dp[0] = 1;
  dp_sum[0] = 0;
  dp_sum[1] = 1;
  for (int i = 1; i < n; i++) {
    rep(j, k) {
      ll cur_l = pr[j].first;
      ll cur_r = pr[j].second;
      if (i - cur_l < 0)
        break;
      if (i - cur_r >= 0) {
        // あとで
        dp[i] += dp_sum[i - cur_l + 1] - dp_sum[i - cur_r];
        dp[i] %= MOD;
      } else {
        for (int k = cur_l; k <= cur_r; k++) {
          if (i - k >= 0) {
            dp[i] += dp[i - k];
            dp[i] %= MOD;
          } else
            break;
        }
      }
    }
    dp_sum[i + 1] = dp[i] + dp_sum[i];
    dp_sum[i + 1] %= MOD;
  }
  if (dp[n - 1] < 0)
    dp[n - 1] += MOD;
  cout << dp[n - 1] << endl;
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, N) for (int i = 0; i < int(N); ++i)
using ll = long long;
const ll MOD = 998244353;
const int INF = 1001001001;
// const ll INF = 1000000000000000000LL;

int main() {
  ll n, k;
  cin >> n >> k;
  vector<pair<ll, ll>> pr(k);
  rep(i, k) {
    ll a, b;
    cin >> a >> b;
    pr[i].first = a;
    pr[i].second = b;
  }
  sort(pr.begin(), pr.end());

  vector<ll> dp(n);
  vector<ll> dp_sum(n + 1);
  dp[0] = 1;
  dp_sum[0] = 0;
  dp_sum[1] = 1;
  for (int i = 1; i < n; i++) {
    rep(j, k) {
      ll cur_l = pr[j].first;
      ll cur_r = pr[j].second;
      if (i - cur_l < 0)
        break;
      if (i - cur_r < 0)
        cur_r = i;
      // if(i-cur_r>=0){
      // あとで
      dp[i] += dp_sum[i - cur_l + 1] - dp_sum[i - cur_r];
      dp[i] %= MOD;
      // }
      // else{
      //     for(int k=cur_l;k<=cur_r;k++){
      //         if(i-k>=0){
      //             dp[i] += dp[i-k];
      //             dp[i]%=MOD;
      //         }
      //         else
      //             break;
      //     }
      // }
    }
    dp_sum[i + 1] = dp[i] + dp_sum[i];
    dp_sum[i + 1] %= MOD;
  }
  if (dp[n - 1] < 0)
    dp[n - 1] += MOD;
  cout << dp[n - 1] << endl;
  return 0;
}


#include <bits/stdc++.h>

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define dump_1(x1) cerr << #x1 << ": " << x1 << endl
#define dump_2(x1, x2)                                                         \\
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define dump_3(x1, x2, x3)                                                     \\
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": "      \\
       << x3 << endl
#define dump_4(x1, x2, x3, x4)                                                 \\
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": "      \\
       << x3 << ", " #x4 << ": " << x4 << endl
#define dump_5(x1, x2, x3, x4, x5)                                             \\
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": "      \\
       << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#define dump(...)                                                              \\
  CHOOSE((__VA_ARGS__, dump_5, dump_4, dump_3, dump_2, dump_1, ~))(__VA_ARGS__)
#define check(s) cerr << s << endl

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

using namespace std;

using ll = long long;

const long long MOD = 998244353;

vector<int> dx = {0, 1, 0, -1};
vector<int> dy = {1, 0, -1, 0};

const ll LINF = 2e18;
const int INF = 1e9;

ll N;
ll K;
std::vector<ll> L;
std::vector<ll> R;

vector<ll> dp;

vector<pair<ll, ll>> f(ll i) {
  vector<pair<ll, ll>> ret;
  rep(k, K) {
    ll l = L.at(k);
    ll r = R.at(k);
    if (i - l > 0) {
      pair<ll, ll> p = {i - l, max(1LL, i - r)};
      ret.push_back(p);
    }
  }
  return ret;
}

void solve() {
  dp.resize(N + 1, 0);
  dp.at(0) = 1;

  rep(i, N) {
    for (auto p : f(i + 2)) {
      ll l = p.second;
      ll r = p.first;
      for (int j = l; j <= r; j++) {
        dp.at(i + 1) += dp.at(j - 1) % MOD;
      }
    }
  }

  cout << dp.at(N - 1) % MOD << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  scanf("%lld", &N);
  scanf("%lld", &K);
  L.resize(K);
  R.resize(K);
  for (int i = 0; i < K; i++) {
    scanf("%lld", &L[i]);
    scanf("%lld", &R[i]);
  }
  solve();
  return 0;
}

#include <bits/stdc++.h>

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define dump_1(x1) cerr << #x1 << ": " << x1 << endl
#define dump_2(x1, x2)                                                         \\
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define dump_3(x1, x2, x3)                                                     \\
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": "      \\
       << x3 << endl
#define dump_4(x1, x2, x3, x4)                                                 \\
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": "      \\
       << x3 << ", " #x4 << ": " << x4 << endl
#define dump_5(x1, x2, x3, x4, x5)                                             \\
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": "      \\
       << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#define dump(...)                                                              \\
  CHOOSE((__VA_ARGS__, dump_5, dump_4, dump_3, dump_2, dump_1, ~))(__VA_ARGS__)
#define check(s) cerr << s << endl

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

using namespace std;

using ll = long long;

const long long MOD = 998244353;

vector<int> dx = {0, 1, 0, -1};
vector<int> dy = {1, 0, -1, 0};

const ll LINF = 2e18;
const int INF = 1e9;

ll N;
ll K;
std::vector<ll> L;
std::vector<ll> R;

vector<ll> dp;

vector<pair<ll, ll>> f(ll i) {
  vector<pair<ll, ll>> ret;
  rep(k, K) {
    ll l = L.at(k);
    ll r = R.at(k);
    if (i - l > 0) {
      pair<ll, ll> p = {i - l, max(1LL, i - r)};
      ret.push_back(p);
    }
  }
  return ret;
}

void solve() {
  dp.resize(N, 0);
  dp.at(0) = 1;

  vector<ll> acc(N + 1, 0);
  acc.at(0) = 0;
  acc.at(1) = 1;

  rep(i, N - 1) {
    for (auto p : f(i + 2)) {
      ll l = p.second - 1;
      ll r = p.first;
      dp.at(i + 1) += (acc.at(r) - acc.at(l) + MOD) % MOD;
      dp.at(i + 1) %= MOD;
    }
    acc.at(i + 2) = (acc.at(i + 1) + dp.at(i + 1)) % MOD;
  }

  cout << dp.at(N - 1) % MOD << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  scanf("%lld", &N);
  scanf("%lld", &K);
  L.resize(K);
  R.resize(K);
  for (int i = 0; i < K; i++) {
    scanf("%lld", &L[i]);
    scanf("%lld", &R[i]);
  }
  solve();
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep3(i, s, n) for (int i = (s); i <= (int)(n); i++)

int a[400010];
int b[200010];

int main() {
  int n;
  int m;
  int k;
  int p, lk, rk;

  m = 998244353;
  p = 0;
  a[1] = 1;

  cin >> n >> k;
  rep(i, k) {
    cin >> lk >> rk;
    rep3(i, lk, rk) {
      b[p] = i;
      p++;
    }
  }
  rep(i, n) {
    if (a[i] == 0)
      continue;
    rep(j, p) {
      a[i + b[j]] += a[i];
      a[i + b[j]] %= m;
    }
  }

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

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep3(i, s, n) for (int i = (s); i <= (int)(n); i++)

int a[200010];
int b[200010];
int lk[20];
int rk[20];

int main() {
  int n;
  int m;
  int k;
  int ans, lkk, rkk;
  long long p;

  m = 998244353;
  a[1] = 1;
  b[1] = 1;

  cin >> n >> k;
  rep(i, k) cin >> lk[i] >> rk[i];
  rep3(i, 2, n + 1) {
    rep(j, k) {
      rkk = max(i - rk[j] - 1, 0);
      lkk = max(i - lk[j], 0);
      p = b[lkk] - b[rkk] + m;
      p %= m;
      a[i] += p;
      a[i] %= m;
    }
    b[i] = b[i - 1] + a[i];
    b[i] %= m;
  }
  ans = a[n] + m;
  ans %= m;

  cout << ans << endl;
  return 0;
}


// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
// #pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
using namespace std;
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
// #include <ext/rope>
// using namespace __gnu_pbds;
// using namespace __gnu_cxx;
// template <typename T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,
// tree_order_statistics_node_update>; #define Find order_of_key #define at
// find_by_order
#define x first
#define y second
#define ll long long
#define lll __int128
#define ull unsigned long long
#define ulll unsigned __int128
#define pii pair<int, int>
#define pb push_back
#define eb emplace_back
#define gu getchar_unlocked()
#define pu putchar_unlocked()
#define all(x) x.begin(), x.end()
#define endl '\\n'

const int mod = 998244353;

const static int mx = 200010;
ll BIT[mx];

void update(ll pos, ll val) {
  for (; pos <= mx; pos += pos & (-pos))
    BIT[pos] += val;
}
ll query(ll pos) {
  ll sum = 0;
  for (; pos > 0; pos -= pos & (-pos))
    sum += BIT[pos];
  return sum;
}

int k;
int L[15], R[15];
int n;
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> L[i] >> R[i];
  }
  update(n, 1);
  for (int i = n - 1; i >= 1; i--) {
    int d = n - i;
    ll ans = 0;
    for (int j = 0; j < k; j++) {
      int l = i + L[j];
      int r = min(i + R[j], n);
      ans += query(r);
      if (l != 1)
        ans -= query(l - 1);
      ans %= mod;
    }
    if (ans < 0)
      ans += mod;
    update(i, ans);
  }
  cout << query(1) << endl;
  return 0;
}

// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
// #pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
using namespace std;
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
// #include <ext/rope>
// using namespace __gnu_pbds;
// using namespace __gnu_cxx;
// template <typename T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,
// tree_order_statistics_node_update>; #define Find order_of_key #define at
// find_by_order
#define x first
#define y second
#define ll long long
#define lll __int128
#define ull unsigned long long
#define ulll unsigned __int128
#define pii pair<int, int>
#define pb push_back
#define eb emplace_back
#define gu getchar_unlocked()
#define pu putchar_unlocked()
#define all(x) x.begin(), x.end()
#define endl '\\n'

const int mod = 998244353;

const static int mx = 200010;
ll BIT[mx];

void update(ll pos, ll val) {
  for (; pos <= mx; pos += pos & (-pos))
    BIT[pos] += val;
}
ll query(ll pos) {
  ll sum = 0;
  for (; pos > 0; pos -= pos & (-pos))
    sum += BIT[pos];
  return sum;
}

int k;
int L[15], R[15];
int n;
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> L[i] >> R[i];
  }
  update(n, 1);
  for (int i = n - 1; i >= 1; i--) {
    int d = n - i;
    ll ans = 0;
    for (int j = 0; j < k; j++) {
      int l = i + L[j];
      int r = min(i + R[j], n);
      if (l <= r) {
        ans += query(r);
        if (l != 1)
          ans -= query(l - 1);
      }
      ans %= mod;
    }
    if (ans < 0)
      ans += mod;
    update(i, ans);
  }
  cout << query(1) << endl;
  return 0;
}


#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cstdint>   // int64_t, int*_t
#include <cstdio>    // printf
#include <deque>     // deque
#include <iomanip>
#include <iostream> // cout, endl, cin
#include <map>      // map
#include <math.h>
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <string>        // string, to_string, stoi
#include <tuple>         // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;
#define int long long

signed main() {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(false);

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

  vector<int> s(n + 1);
  for (int i = 0; i < k; i++) {
    for (int j = l.at(i); j < r.at(i) + 1; j++) {
      s.at(j) = 1;
    }
  }

  vector<int> ans(n + 1);

  ans.at(1) = 1;
  for (int i = 2; i < n + 1; i++) {
    for (int j = 1; j < i; j++) {
      ans.at(i) += ans.at(i - j) * s.at(j);
      ans.at(i) %= 998244353;
    }
  }

  cout << ans.at(n) << endl;
}

#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cstdint>   // int64_t, int*_t
#include <cstdio>    // printf
#include <deque>     // deque
#include <iomanip>
#include <iostream> // cout, endl, cin
#include <map>      // map
#include <math.h>
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <string>        // string, to_string, stoi
#include <tuple>         // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;
#define int long long

signed main() {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(false);

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

  vector<int> s(n + 1);
  for (int i = 0; i < k; i++) {
    for (int j = l.at(i); j < r.at(i) + 1; j++) {
      s.at(j) = 1;
    }
  }

  vector<int> ans(n + 1);
  vector<int> ansruiseki(n + 1);

  ans.at(1) = 1;
  ansruiseki.at(1) = 1;

  for (int i = 2; i < n + 1; i++) {
    int tmpruiseki = 0;
    for (int j = 0; j < k; j++) {
      if (l.at(j) >= i)
        continue;
      int tmpmax = min(r.at(j), i - 1);
      tmpruiseki += ansruiseki.at(i - l.at(j)) - ansruiseki.at(i - tmpmax - 1);
      //            tmpruiseki %= 998244353;
      //            cout << i << " " << j << " " << tmpmax << " " << l.at(j)-1
      //            << endl; cout << ansruiseki.at(i-l.at(j)) << " " <<
      //            ansruiseki.at(i-tmpmax-1) << endl;
    }
    ans.at(i) = tmpruiseki;
    ans.at(i) %= 998244353;
    ansruiseki.at(i) = ansruiseki.at(i - 1) + ans.at(i);
    //        ansruiseki.at(i) %= 998244353;
    //        cout << ans.at(i) << " " << ansruiseki.at(i) << endl;
  }

  /*    for(int i = 0;i < n;i ++){
          cout << ans.at(i) << endl;
      }
  */
  cout << ans.at(n) % 998244353 << endl;
}


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

using namespace std;

int main() {
  int32_t N, K;
  cin >> N >> K;
  vector<pair<int32_t, int32_t>> lrs(K);
  for (int32_t k = 0; k < K; ++k) {
    cin >> lrs[k].first >> lrs[k].second;
  }

  vector<uint32_t> dp{1};

  for (int32_t i = 1; i < N; ++i) {
    dp.push_back(0);
    uint32_t &cdp = dp[i];
    for (const auto &lr : lrs) {
      int32_t e = i - lr.first;
      int32_t s = max(0, i - lr.second);
      if (e < 0) {
        continue;
      }

      for (int32_t j = s; j <= e; ++j) {
        cdp += dp[j];
        cdp %= 998244353;
      }
    }
  }

  cout << dp[N - 1];
}

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

using namespace std;

int main() {
  int32_t N, K;
  cin >> N >> K;
  vector<pair<int32_t, int32_t>> lrs(K);
  for (int32_t k = 0; k < K; ++k) {
    cin >> lrs[k].first >> lrs[k].second;
  }

  vector<uint32_t> dp{1};
  vector<int64_t> hs(K);

  for (int32_t i = 1; i < N; ++i) {
    dp.push_back(0);
    uint32_t &cdp = dp[i];
    for (int32_t k = 0; k < K; ++k) {
      const auto &lr = lrs[k];
      auto &h = hs[k];
      int32_t e = i - lr.first;
      int32_t s = i - lr.second;

      if (e < 0) {
        continue;
      }

      h += dp[e];

      if (s > 0) {
        h -= dp[s - 1];
        if (h < 0) {
          h += 998244353;
        }
      }

      cdp = (cdp + h) % 998244353;
    }
  }

  cout << dp[N - 1];
}


#define errOut(s)                                                              \\
  { std::cerr << __LINE__ << ":" << #s << ":" << (s) << std::endl; }
#define errOutSeparator(s)                                                     \\
  { std::cerr << __LINE__ << ":" << #s << ":" << (s) << "======" << std::endl; }

#include <bits/stdc++.h>

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Weverything"
// #include <boost/multi_array.hpp>
// #include <boost/optional.hpp>
// #include <boost/range/adaptors.hpp>
// #include <boost/range/algorithm.hpp>
// #include <boost/range/irange.hpp>
#pragma clang diagnostic pop

using namespace std;
using range_t = struct {
  int64_t l;
  int64_t r;
};
std::ostream &operator<<(std::ostream &os, const range_t &r) {
  os << "Range L:" << r.l << " R:" << r.r << ";";
  return os;
}

using reachable_t = struct {
  int64_t r;
  int64_t v;
};
std::ostream &operator<<(std::ostream &os, const reachable_t &r) {
  os << "Reachable R:" << r.r << " V:" << r.v << ";";
  return os;
}

static constexpr int64_t MaxN = 200000;
static constexpr int64_t MaxK = 10;
static constexpr int64_t MOD = 998244353;
static std::vector<range_t> rgs;
static std::array<reachable_t, MaxN> reachables;
static int64_t n;

void addToReachable(int64_t l, int64_t r, int64_t v) {
  r = std::min(r, n - 1);
  if (l > r) {
    return;
  }
  if (reachables[l].v == 0) {
    reachables[l].r = r;
    reachables[l].v = v;
    return;
  }
  if (reachables[l].r == r) {
    reachables[l].v += v;
    reachables[l].v %= MOD;
    return;
  }

  if (reachables[l].r > r) {
    addToReachable(r + 1, reachables[l].r, reachables[l].v);
    reachables[l].r = r;
    reachables[l].v += v;
    return;
  }

  addToReachable(reachables[l].r + 1, r, v);
  reachables[l].v += v;
  reachables[l].v %= MOD;
}

int64_t solve(void) {
  std::sort(rgs.begin(), rgs.end(),
            [](auto const &lhv, auto const &rhv) { return lhv.l < rhv.l; });
  reachables[0].r = 0;
  reachables[0].v = 1;
  for (auto i = 0; i < n - 1; i++) {
    auto const &r = reachables[i];
    if (r.v == 0) {
      continue;
    }
    if (r.r != i) {
      addToReachable(i + 1, r.r, r.v);
    }
    for (auto const &rg : rgs) {
      if (i + rg.l >= n) {
        break;
      }
      addToReachable(i + rg.l, i + rg.r, r.v);
    }
  }
  return reachables[n - 1].v;
}

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  std::cin >> n;
  int64_t k;
  std::cin >> k;
  rgs.resize(k);
  for (int i = 0; i < k; i++) {
    std::cin >> rgs[i].l;
    std::cin >> rgs[i].r;
  }
  auto const res = solve();
  std::cout << res << std::endl;
  return 0;
}

#define errOut(s)                                                              \\
  { std::cerr << __LINE__ << ":" << #s << ":" << (s) << std::endl; }
#define errOutSeparator(s)                                                     \\
  { std::cerr << __LINE__ << ":" << #s << ":" << (s) << "======" << std::endl; }

#include <bits/stdc++.h>

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Weverything"
// #include <boost/multi_array.hpp>
// #include <boost/optional.hpp>
// #include <boost/range/adaptors.hpp>
// #include <boost/range/algorithm.hpp>
// #include <boost/range/irange.hpp>
#pragma clang diagnostic pop

using namespace std;
using range_t = struct {
  int64_t l;
  int64_t r;
};
std::ostream &operator<<(std::ostream &os, const range_t &r) {
  os << "Range L:" << r.l << " R:" << r.r << ";";
  return os;
}

static constexpr int64_t MaxN = 200000;
static constexpr int64_t MaxK = 10;
static constexpr int64_t MOD = 998244353;
static std::vector<range_t> rgs;
static std::array<int64_t, MaxN> diffs;
static std::array<int64_t, MaxN> values;
static int64_t n;

int64_t solve(void) {
  std::sort(rgs.begin(), rgs.end(),
            [](auto const &lhv, auto const &rhv) { return lhv.l < rhv.l; });
  values[0] = 1;
  diffs[0] = 1;
  diffs[1] = -1;
  for (auto i = 0; i < n; i++) {
    if (i > 0) {
      values[i] = values[i - 1] + diffs[i];
      values[i] %= MOD;
    }
    for (auto const &rg : rgs) {
      if (i + rg.l >= n) {
        break;
      }
      diffs[i + rg.l] += values[i];
      diffs[i + rg.l] %= MOD;
      if (i + rg.r + 1 >= n) {
        break;
      }
      diffs[i + rg.r + 1] -= values[i];
      if (diffs[i + rg.r + 1] < 0) {
        diffs[i + rg.r + 1] += MOD;
      } else {
        diffs[i + rg.r + 1] %= MOD;
      }
    }
  }
  return values[n - 1];
}

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  std::cin >> n;
  int64_t k;
  std::cin >> k;
  rgs.resize(k);
  for (int i = 0; i < k; i++) {
    std::cin >> rgs[i].l;
    std::cin >> rgs[i].r;
  }
  auto const res = solve();
  std::cout << res << std::endl;
  return 0;
}


#include <bits/stdc++.h>
/*
CE
#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<deque>
#include<iostream>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<vector>

*/
using namespace std;
#define rep(i, a, n) for (int i = a; i <= n; i++)
#define per(i, a, n) for (int i = n; i >= a; i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define mem(a, b) memset(a, b, sizeof(a))
#define ios                                                                    \\
  std::ios::sync_with_stdio(false);                                            \\
  std::cin.tie(0);                                                             \\
  std::cout.tie(0);
// ios  can not be used with scanf,printf.  IF  ios MUST cin,cout.
typedef long long ll;
typedef vector<int> VI;
typedef pair<int, int> PII;
const ll mod = 998244353;
const int INF = 0x3f3f3f3f;
ll ksm(ll a, ll b) {
  ll res = 1;
  a %= mod;
  for (; b; b >>= 1) {
    if (b & 1)
      res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

const int N = 1e5 + 10;
int n, k;
ll sum[N], dp[N];
int L[N], R[N];
ll get(int l, int r) {
  if (l <= 1)
    l = 1;
  return ((sum[r] - sum[l - 1]) % mod + mod) % mod;
}
int main() {
  scanf("%d%d", &n, &k);
  rep(i, 1, k) { scanf("%d%d", &L[i], &R[i]); }
  dp[1] = sum[1] = 1;
  rep(i, 1, n) {
    rep(j, 1, k) { dp[i] = (dp[i] + get(i - R[j], i - L[j])) % mod; }
    sum[i] = sum[i - 1] + dp[i];
  }
  printf("%lld\\n", dp[n]);
  return 0;
}

#include <bits/stdc++.h>
/*
CE
#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<deque>
#include<iostream>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<vector>

*/
using namespace std;
#define rep(i, a, n) for (int i = a; i <= n; i++)
#define per(i, a, n) for (int i = n; i >= a; i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define mem(a, b) memset(a, b, sizeof(a))
#define ios                                                                    \\
  std::ios::sync_with_stdio(false);                                            \\
  std::cin.tie(0);                                                             \\
  std::cout.tie(0);
// ios  can not be used with scanf,printf.  IF  ios MUST cin,cout.
typedef long long ll;
typedef vector<int> VI;
typedef pair<int, int> PII;
const ll mod = 998244353;
const int INF = 0x3f3f3f3f;
ll ksm(ll a, ll b) {
  ll res = 1;
  a %= mod;
  for (; b; b >>= 1) {
    if (b & 1)
      res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

const int N = 2e5 + 10;
int n, k;
ll sum[N], dp[N];
int L[N], R[N];
ll get(int l, int r) {
  if (l <= 1)
    l = 1;
  return ((sum[r] - sum[l - 1]) % mod + mod) % mod;
}
int main() {
  scanf("%d%d", &n, &k);
  rep(i, 1, k) { scanf("%d%d", &L[i], &R[i]); }
  dp[1] = sum[1] = 1;
  rep(i, 1, n) {
    rep(j, 1, k) { dp[i] = (dp[i] + get(i - R[j], i - L[j])) % mod; }
    sum[i] = sum[i - 1] + dp[i];
  }
  printf("%lld\\n", dp[n]);
  return 0;
}


#include "bits/stdc++.h"
#include "math.h"

using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll, ll> P;
typedef vector<P> vp;
#define rep(i, a, b) for (ll i = (a); i < (b); ++i)
#define drep(i, a, b) for (ll i = (a); i >= (b); --i)
#define SIZE(a) ll((a).size())
#define out(a) cout << (a) << endl;
const int inf = INT_MAX;
const int MAX = 510000;
const ll MOD = 998244353;

int main() {
  ll n, k;
  cin >> n >> k;
  vb ok(n + 1, false);
  rep(i, 0, k) {
    ll l, r;
    cin >> l >> r;
    rep(i, l, r + 1) { ok[i] = true; }
  }
  vll dp(n, 0);
  dp[0] = 1;
  rep(i, 1, n) {
    rep(u, 1, i + 1) {
      if (ok[u]) {
        dp[i] += dp[i - u];
        dp[i] %= MOD;
      }
    }
  }
  out(dp[n - 1] % MOD);
}

#include "bits/stdc++.h"
#include "math.h"

using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll, ll> P;
typedef vector<P> vp;
#define rep(i, a, b) for (ll i = (a); i < (b); ++i)
#define drep(i, a, b) for (ll i = (a); i >= (b); --i)
#define SIZE(a) ll((a).size())
#define out(a) cout << (a) << endl;
const int inf = INT_MAX;
const int MAX = 510000;
const ll MOD = 998244353;

int main() {
  ll n, k;
  cin >> n >> k;
  vll l(k), r(k);
  rep(i, 0, k) { cin >> l[i] >> r[i]; }
  vll dp(n, 0), sdp(n + 1, 0);
  dp[0] = 1;
  sdp[1] = 1;
  rep(i, 1, n) {
    rep(j, 0, k) {
      ll left = max(0LL, i - r[j]), right = max(0LL, i - l[j] + 1);
      dp[i] += sdp[right] - sdp[left];
      dp[i] %= MOD;
    }
    sdp[i + 1] = sdp[i] + dp[i];
  }

  out(dp[n - 1] % MOD);
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define drep(i, n) for (int i = (n - 1); i >= 0; i--)
#define all(v) (v).begin(), (v).end()
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
// const ll MOD = 1e9+7;
const ll MOD = 998244353;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  vector<int> s;
  rep(i, k) {
    int l, r;
    cin >> l >> r;
    for (int d = l; d <= r; d++) {
      s.push_back(d);
    }
  }
  vector<ll> dp(n);
  dp[0] = 1;
  rep(i, n - 1) {
    for (int d : s) {
      if (i + 1 >= d) {
        dp[i + 1] += dp[i + 1 - d];
        dp[i + 1] %= MOD;
      }
    }
  }
  cout << dp[n - 1] << endl;
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define drep(i, n) for (int i = (n - 1); i >= 0; i--)
#define all(v) (v).begin(), (v).end()
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
// const ll MOD = 1e9+7;
const ll MOD = 998244353;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  vector<P> s;
  rep(i, k) {
    int l, r;
    cin >> l >> r;
    s.push_back(make_pair(l, r));
  }
  vector<ll> dp(2 * n);
  dp[n] = 1;
  ll cum = 0;
  rep(i, n - 1) {
    for (P p : s) {
      cum += dp[i + n + 1 - p.first];
      cum -= dp[i + n + 1 - p.second - 1];
      cum += 2 * MOD;
      cum %= MOD;
    }
    dp[i + n + 1] = cum;
  }
  cout << dp[2 * n - 1] << endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\\n'
#define mod 998244353
#define pb push_back
#define ff first
#define ss second
#define con continue
#define ub upper_bound
#define lb lower_bound
#define sum(a) (accumulate((a).begin(), (a).end(), 0ll))
#define mine(a) (*min_element((a).begin(), (a).end()))
#define maxe(a) (*max_element((a).begin(), (a).end()))
#define mini(a) (min_element((a).begin(), (a).end()) - (a).begin())
#define maxi(a) (max_element((a).begin(), (a).end()) - (a).begin())
#define lowb(a, x) (lower_bound((a).begin(), (a).end(), (x)) - (a).begin())
#define uppb(a, x) (upper_bound((a).begin(), (a).end(), (x)) - (a).begin())

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

const int dx8[] = {-1, 0, 1, 0, 1, 1, -1, -1};
const int dy8[] = {0, -1, 0, 1, 1, -1, 1, -1};
vector<ll> dp, j;
ll solve(ll pos) {

  if (pos == dp.size() - 1)
    return 1;
  if (dp[pos] != -1)
    return dp[pos];
  ll ans = 0;
  for (auto x : j) {
    if (x + pos >= dp.size())
      break;
    ans = (ans % mod + solve(x + pos) % mod) % mod;
  }
  dp[pos] = ans;
  return ans;
}

void solve() {
  ll n;
  cin >> n;
  dp.clear();
  dp.resize(n, -1);
  j.clear();

  ll k;
  cin >> k;
  for (ll i = 0; i < k; i++) {
    ll x, y;
    cin >> x >> y;
    for (ll j1 = x; j1 <= y; j1++)
      j.pb(j1);
  }

  sort(j.begin(), j.end());
  cout << solve(0) << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\\n'
#define mod 998244353
#define pb push_back
#define ff first
#define ss second
#define con continue
#define ub upper_bound
#define lb lower_bound
#define sum(a) (accumulate((a).begin(), (a).end(), 0ll))
#define mine(a) (*min_element((a).begin(), (a).end()))
#define maxe(a) (*max_element((a).begin(), (a).end()))
#define mini(a) (min_element((a).begin(), (a).end()) - (a).begin())
#define maxi(a) (max_element((a).begin(), (a).end()) - (a).begin())
#define lowb(a, x) (lower_bound((a).begin(), (a).end(), (x)) - (a).begin())
#define uppb(a, x) (upper_bound((a).begin(), (a).end(), (x)) - (a).begin())

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

const int dx8[] = {-1, 0, 1, 0, 1, 1, -1, -1};
const int dy8[] = {0, -1, 0, 1, 1, -1, 1, -1};

void solve() {
  ll n, k;
  cin >> n >> k;
  vector<ll> dp(n + 1, 0);
  vector<pair<ll, ll>> q;

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

    ll a, b;
    cin >> a >> b;
    q.pb({a, b});
  }
  dp[0] = 1;
  for (ll i = 0; i < n; i++) {

    for (ll j = 0; j < k; j++) {
      ll x, y;
      x = i + q[j].ff;
      y = i + q[j].ss;
      if (x >= n)
        continue;
      y = min(y, n - 1);
      dp[x] = (dp[x] % mod + dp[i] % mod) % mod;
      dp[y + 1] = (dp[y + 1] % mod - dp[i] % mod + mod) % mod;
    }
    if (i == 0)
      continue;
    dp[i + 1] = (dp[i + 1] % mod + dp[i] % mod) % mod;
  }
  cout << dp[n - 1] << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
}


#include <bits/stdc++.h>

#define ntest 0
#define l first
#define r second

using namespace std;
const int mod = 998244353;
int n, k;
pair<int, int> seg[11];
long long dp[100005], f[100005];
void solve() {
  cin >> n >> k;
  for (int i = 1; i <= k; ++i)
    cin >> seg[i].l >> seg[i].r;
  dp[1] = 1;
  f[1] = 1;
  for (int i = 2; i <= n; ++i) {
    for (int j = 1; j <= k; ++j) {
      int s = max(0, i - seg[j].l);
      int e = max(1, i - seg[j].r);
      dp[i] = (dp[i] + (f[s] - f[e - 1] + mod) % mod) % mod;
    }
    f[i] = (f[i - 1] + dp[i]) % mod;
  }
  cout << dp[n];
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  if (ntest) {
    int t;
    cin >> t;
    while (t--)
      solve();
  } else {
    solve();
  }
}

#include <bits/stdc++.h>

#define ntest 0
#define l first
#define r second

using namespace std;
const int mod = 998244353;
int n, k;
pair<int, int> seg[11];
long long dp[200005], f[200005];
void solve() {
  cin >> n >> k;
  for (int i = 1; i <= k; ++i)
    cin >> seg[i].l >> seg[i].r;
  dp[1] = 1;
  f[1] = 1;
  for (int i = 2; i <= n; ++i) {
    for (int j = 1; j <= k; ++j) {
      int s = max(0, i - seg[j].l);
      int e = max(1, i - seg[j].r);
      dp[i] = (dp[i] + (f[s] - f[e - 1] + mod) % mod) % mod;
    }
    f[i] = (f[i - 1] + dp[i]) % mod;
  }
  cout << dp[n];
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  if (ntest) {
    int t;
    cin >> t;
    while (t--)
      solve();
  } else {
    solve();
  }
}


// Tonight's the night and it is going to happen again and again.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define T                                                                      \\
  ll t;                                                                        \\
  cin >> t;                                                                    \\
  while (t--)
#define mod 998244353
#define inf 1000000000000000000
#define mem(name, val) memset(name, val, sizeof(name))
#define f(n) for (ll i = 0; i < n; i++)
#define rep(i, a, n) for (ll i = a; i < n; i++)
#define endl "\\n"
ll gcd(ll a, ll b) {
  if (b == 0) {
    return a;
  }
  return gcd(b, a % b);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ll n, l, r, k;
  cin >> n >> k;
  set<ll> s;
  f(k) {
    cin >> l >> r;
    for (int i = l; i <= r; i++) {
      s.insert(i);
    }
  }
  ll wt = n - 1;
  ll dp[n + 3];
  mem(dp, 0);
  dp[0] = 1;
  for (ll i = 1; i <= wt; i++) {
    for (auto it = s.begin(); it != s.end(); it++) {
      // cout<<*it<<endl;
      if (*it <= i) {
        dp[i] += dp[i - (*it)];
        dp[i] %= mod;
      } else {
        break;
      }
    }
  }
  // for(auto t:dp){cout<<t<<endl;}
  cout << dp[wt] % mod;
}

// Tonight's the night and it is going to happen again and again.
// this solution was copied from youtube solution but now i understand this
// fully as of this date
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define T                                                                      \\
  ll t;                                                                        \\
  cin >> t;                                                                    \\
  while (t--)
#define mod 998244353
#define inf 1000000000000000000
#define mem(name, val) memset(name, val, sizeof(name))
#define f(n) for (ll i = 0; i < n; i++)
#define rep(i, a, n) for (ll i = a; i < n; i++)
#define endl "\\n"
ll gcd(ll a, ll b) {
  if (b == 0) {
    return a;
  }
  return gcd(b, a % b);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ll n, k;
  cin >> n >> k;
  ll l[k], r[k];
  f(k) { cin >> l[i] >> r[i]; }
  ll dp[n + 1];
  mem(dp, 0);
  ll dpsum[n + 1];
  mem(dpsum, 0);
  dpsum[1] = 1;
  dp[1] = 1;
  for (ll i = 2; i <= n; i++) {
    for (ll j = 0; j < k; j++) {
      ll li = i - r[j];
      ll ri = i - l[j];
      if (ri < 0) {
        continue;
      }
      li = max(li, 1ll);
      dp[i] += dpsum[ri] - dpsum[li - 1];
      if (dp[i] < 0) {
        dp[i] += mod;
      } else {
        dp[i] %= mod;
      }
    }
    dpsum[i] = (dpsum[i - 1] + dp[i]) % mod;
  }
  // for(auto t:dp){cout<<t<<" ";}
  cout << dp[n] % mod << endl;
}


#include <bits/stdc++.h>

#ifdef LOCAL
#include <debug.hpp>
#else
#define debug(...) void()
#endif

using namespace std;

template <typename T> T inverse(T a, T m) {
  T u = 0, v = 1;
  while (a != 0) {
    T t = m / a;
    m -= t * a;
    swap(a, m);
    u -= t * v;
    swap(u, v);
  }
  assert(m == 1);
  return u;
}

template <typename T> class Modular {
public:
  using Type = typename decay<decltype(T::value)>::type;

  constexpr Modular() : value() {}
  template <typename U> Modular(const U &x) { value = normalize(x); }

  template <typename U> static Type normalize(const U &x) {
    Type v;
    if (-mod() <= x && x < mod()) {
      v = static_cast<Type>(x);
    } else {
      v = static_cast<Type>(x % mod());
    }
    if (v < 0)
      v += mod();
    return v;
  }

  const Type &operator()() const { return value; }
  template <typename U> explicit operator U() const {
    return static_cast<U>(value);
  }
  constexpr static Type mod() { return T::value; }

  Modular &operator+=(const Modular &other) {
    if ((value += other.value) >= mod())
      value -= mod();
    return *this;
  }
  Modular &operator-=(const Modular &other) {
    if ((value -= other.value) < 0)
      value += mod();
    return *this;
  }
  template <typename U> Modular &operator+=(const U &other) {
    return *this += Modular(other);
  }
  template <typename U> Modular &operator-=(const U &other) {
    return *this -= Modular(other);
  }
  Modular &operator++() { return *this += 1; }
  Modular &operator--() { return *this -= 1; }
  Modular operator++(int) {
    Modular result(*this);
    *this += 1;
    return result;
  }
  Modular operator--(int) {
    Modular result(*this);
    *this -= 1;
    return result;
  }
  Modular operator-() const { return Modular(-value); }

  template <typename U = T>
  typename enable_if<is_same<typename Modular<U>::Type, int>::value,
                     Modular>::type &
  operator*=(const Modular &rhs) {
#ifdef _WIN32
    uint64_t x = static_cast<int64_t>(value) * static_cast<int64_t>(rhs.value);
    uint32_t xh = static_cast<uint32_t>(x >> 32), xl = static_cast<uint32_t>(x),
             d, m;
    asm("divl %4; \\n\\t" : "=a"(d), "=d"(m) : "d"(xh), "a"(xl), "r"(mod()));
    value = m;
#else
    value = normalize(static_cast<int64_t>(value) *
                      static_cast<int64_t>(rhs.value));
#endif
    return *this;
  }
  template <typename U = T>
  typename enable_if<is_same<typename Modular<U>::Type, int64_t>::value,
                     Modular>::type &
  operator*=(const Modular &rhs) {
    int64_t q = static_cast<int64_t>(static_cast<long double>(value) *
                                     rhs.value / mod());
    value = normalize(value * rhs.value - q * mod());
    return *this;
  }
  template <typename U = T>
  typename enable_if<!is_integral<typename Modular<U>::Type>::value,
                     Modular>::type &
  operator*=(const Modular &rhs) {
    value = normalize(value * rhs.value);
    return *this;
  }

  Modular &operator/=(const Modular &other) {
    return *this *= Modular(inverse(other.value, mod()));
  }

  template <typename U> friend const Modular<U> &abs(const Modular<U> &v) {
    return v;
  }

  template <typename U>
  friend bool operator==(const Modular<U> &lhs, const Modular<U> &rhs);

  template <typename U>
  friend bool operator<(const Modular<U> &lhs, const Modular<U> &rhs);

  template <typename U>
  friend std::istream &operator>>(std::istream &stream, Modular<U> &number);

private:
  Type value;
};

template <typename T>
bool operator==(const Modular<T> &lhs, const Modular<T> &rhs) {
  return lhs.value == rhs.value;
}
template <typename T, typename U>
bool operator==(const Modular<T> &lhs, U rhs) {
  return lhs == Modular<T>(rhs);
}
template <typename T, typename U>
bool operator==(U lhs, const Modular<T> &rhs) {
  return Modular<T>(lhs) == rhs;
}

template <typename T>
bool operator!=(const Modular<T> &lhs, const Modular<T> &rhs) {
  return !(lhs == rhs);
}
template <typename T, typename U>
bool operator!=(const Modular<T> &lhs, U rhs) {
  return !(lhs == rhs);
}
template <typename T, typename U>
bool operator!=(U lhs, const Modular<T> &rhs) {
  return !(lhs == rhs);
}

template <typename T>
bool operator<(const Modular<T> &lhs, const Modular<T> &rhs) {
  return lhs.value < rhs.value;
}

template <typename T>
Modular<T> operator+(const Modular<T> &lhs, const Modular<T> &rhs) {
  return Modular<T>(lhs) += rhs;
}
template <typename T, typename U>
Modular<T> operator+(const Modular<T> &lhs, U rhs) {
  return Modular<T>(lhs) += rhs;
}
template <typename T, typename U>
Modular<T> operator+(U lhs, const Modular<T> &rhs) {
  return Modular<T>(lhs) += rhs;
}

template <typename T>
Modular<T> operator-(const Modular<T> &lhs, const Modular<T> &rhs) {
  return Modular<T>(lhs) -= rhs;
}
template <typename T, typename U>
Modular<T> operator-(const Modular<T> &lhs, U rhs) {
  return Modular<T>(lhs) -= rhs;
}
template <typename T, typename U>
Modular<T> operator-(U lhs, const Modular<T> &rhs) {
  return Modular<T>(lhs) -= rhs;
}

template <typename T>
Modular<T> operator*(const Modular<T> &lhs, const Modular<T> &rhs) {
  return Modular<T>(lhs) *= rhs;
}
template <typename T, typename U>
Modular<T> operator*(const Modular<T> &lhs, U rhs) {
  return Modular<T>(lhs) *= rhs;
}
template <typename T, typename U>
Modular<T> operator*(U lhs, const Modular<T> &rhs) {
  return Modular<T>(lhs) *= rhs;
}

template <typename T>
Modular<T> operator/(const Modular<T> &lhs, const Modular<T> &rhs) {
  return Modular<T>(lhs) /= rhs;
}
template <typename T, typename U>
Modular<T> operator/(const Modular<T> &lhs, U rhs) {
  return Modular<T>(lhs) /= rhs;
}
template <typename T, typename U>
Modular<T> operator/(U lhs, const Modular<T> &rhs) {
  return Modular<T>(lhs) /= rhs;
}

template <typename T, typename U>
Modular<T> power(const Modular<T> &a, const U &b) {
  assert(b >= 0);
  Modular<T> x = a, res = 1;
  U p = b;
  while (p > 0) {
    if (p & 1)
      res *= x;
    x *= x;
    p >>= 1;
  }
  return res;
}

template <typename T> bool IsZero(const Modular<T> &number) {
  return number() == 0;
}

template <typename T> string to_string(const Modular<T> &number) {
  return to_string(number());
}

template <typename T>
std::ostream &operator<<(std::ostream &stream, const Modular<T> &number) {
  return stream << number();
}

template <typename T>
std::istream &operator>>(std::istream &stream, Modular<T> &number) {
  typename common_type<typename Modular<T>::Type, int64_t>::type x;
  stream >> x;
  number.value = Modular<T>::normalize(x);
  return stream;
}

// using ModType = int;

// struct VarMod { static ModType value; };
// ModType VarMod::value;
// ModType& md = VarMod::value;
// using Mint = Modular<VarMod>;

constexpr int md = 998244353;
using Mint = Modular<std::integral_constant<decay<decltype(md)>::type, md>>;

vector<Mint> fact(1, 1);
vector<Mint> inv_fact(1, 1);

Mint C(int n, int k) {
  if (k < 0 || k > n)
    return 0;
  while ((int)fact.size() < n + 1) {
    fact.emplace_back(fact.back() * (int)fact.size());
    inv_fact.emplace_back(1 / fact.back());
  }
  return fact[n] * inv_fact[k] * inv_fact[n - k];
}

// Mint C(int n, int k) {
//   Mint res = 1;
//   for (int i = 1; i <= k; i++) {
//     res = res * Mint(n - i + 1) / Mint(i);
//   }
//   return res;
// }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> l(k), r(k);
  for (int i = 0; i < k; i++) {
    cin >> l[i] >> r[i];
  }
  int mx = 2 * n;
  vector<Mint> dp(mx, 0);
  dp[0] = 1;
  for (int i = 0; i < n; i++) {
    vector<Mint> dp2(mx, 0);
    for (int j = 0; j < k; j++) {
      dp2[i + l[j]] += dp[i];
      dp2[i + r[j] + 1] -= dp[i];
    }
    for (int i = 1; i < mx; i++) {
      dp2[i] += dp2[i - 1];
    }
    for (int i = 0; i < mx; i++) {
      dp[i] += dp2[i];
    }
  }
  cout << dp[n - 1] << '\\n';
  return 0;
}

#include <bits/stdc++.h>

#ifdef LOCAL
#include <debug.hpp>
#else
#define debug(...) void()
#endif

using namespace std;

template <typename T> T inverse(T a, T m) {
  T u = 0, v = 1;
  while (a != 0) {
    T t = m / a;
    m -= t * a;
    swap(a, m);
    u -= t * v;
    swap(u, v);
  }
  assert(m == 1);
  return u;
}

template <typename T> class Modular {
public:
  using Type = typename decay<decltype(T::value)>::type;

  constexpr Modular() : value() {}
  template <typename U> Modular(const U &x) { value = normalize(x); }

  template <typename U> static Type normalize(const U &x) {
    Type v;
    if (-mod() <= x && x < mod()) {
      v = static_cast<Type>(x);
    } else {
      v = static_cast<Type>(x % mod());
    }
    if (v < 0)
      v += mod();
    return v;
  }

  const Type &operator()() const { return value; }
  template <typename U> explicit operator U() const {
    return static_cast<U>(value);
  }
  constexpr static Type mod() { return T::value; }

  Modular &operator+=(const Modular &other) {
    if ((value += other.value) >= mod())
      value -= mod();
    return *this;
  }
  Modular &operator-=(const Modular &other) {
    if ((value -= other.value) < 0)
      value += mod();
    return *this;
  }
  template <typename U> Modular &operator+=(const U &other) {
    return *this += Modular(other);
  }
  template <typename U> Modular &operator-=(const U &other) {
    return *this -= Modular(other);
  }
  Modular &operator++() { return *this += 1; }
  Modular &operator--() { return *this -= 1; }
  Modular operator++(int) {
    Modular result(*this);
    *this += 1;
    return result;
  }
  Modular operator--(int) {
    Modular result(*this);
    *this -= 1;
    return result;
  }
  Modular operator-() const { return Modular(-value); }

  template <typename U = T>
  typename enable_if<is_same<typename Modular<U>::Type, int>::value,
                     Modular>::type &
  operator*=(const Modular &rhs) {
#ifdef _WIN32
    uint64_t x = static_cast<int64_t>(value) * static_cast<int64_t>(rhs.value);
    uint32_t xh = static_cast<uint32_t>(x >> 32), xl = static_cast<uint32_t>(x),
             d, m;
    asm("divl %4; \\n\\t" : "=a"(d), "=d"(m) : "d"(xh), "a"(xl), "r"(mod()));
    value = m;
#else
    value = normalize(static_cast<int64_t>(value) *
                      static_cast<int64_t>(rhs.value));
#endif
    return *this;
  }
  template <typename U = T>
  typename enable_if<is_same<typename Modular<U>::Type, int64_t>::value,
                     Modular>::type &
  operator*=(const Modular &rhs) {
    int64_t q = static_cast<int64_t>(static_cast<long double>(value) *
                                     rhs.value / mod());
    value = normalize(value * rhs.value - q * mod());
    return *this;
  }
  template <typename U = T>
  typename enable_if<!is_integral<typename Modular<U>::Type>::value,
                     Modular>::type &
  operator*=(const Modular &rhs) {
    value = normalize(value * rhs.value);
    return *this;
  }

  Modular &operator/=(const Modular &other) {
    return *this *= Modular(inverse(other.value, mod()));
  }

  template <typename U> friend const Modular<U> &abs(const Modular<U> &v) {
    return v;
  }

  template <typename U>
  friend bool operator==(const Modular<U> &lhs, const Modular<U> &rhs);

  template <typename U>
  friend bool operator<(const Modular<U> &lhs, const Modular<U> &rhs);

  template <typename U>
  friend std::istream &operator>>(std::istream &stream, Modular<U> &number);

private:
  Type value;
};

template <typename T>
bool operator==(const Modular<T> &lhs, const Modular<T> &rhs) {
  return lhs.value == rhs.value;
}
template <typename T, typename U>
bool operator==(const Modular<T> &lhs, U rhs) {
  return lhs == Modular<T>(rhs);
}
template <typename T, typename U>
bool operator==(U lhs, const Modular<T> &rhs) {
  return Modular<T>(lhs) == rhs;
}

template <typename T>
bool operator!=(const Modular<T> &lhs, const Modular<T> &rhs) {
  return !(lhs == rhs);
}
template <typename T, typename U>
bool operator!=(const Modular<T> &lhs, U rhs) {
  return !(lhs == rhs);
}
template <typename T, typename U>
bool operator!=(U lhs, const Modular<T> &rhs) {
  return !(lhs == rhs);
}

template <typename T>
bool operator<(const Modular<T> &lhs, const Modular<T> &rhs) {
  return lhs.value < rhs.value;
}

template <typename T>
Modular<T> operator+(const Modular<T> &lhs, const Modular<T> &rhs) {
  return Modular<T>(lhs) += rhs;
}
template <typename T, typename U>
Modular<T> operator+(const Modular<T> &lhs, U rhs) {
  return Modular<T>(lhs) += rhs;
}
template <typename T, typename U>
Modular<T> operator+(U lhs, const Modular<T> &rhs) {
  return Modular<T>(lhs) += rhs;
}

template <typename T>
Modular<T> operator-(const Modular<T> &lhs, const Modular<T> &rhs) {
  return Modular<T>(lhs) -= rhs;
}
template <typename T, typename U>
Modular<T> operator-(const Modular<T> &lhs, U rhs) {
  return Modular<T>(lhs) -= rhs;
}
template <typename T, typename U>
Modular<T> operator-(U lhs, const Modular<T> &rhs) {
  return Modular<T>(lhs) -= rhs;
}

template <typename T>
Modular<T> operator*(const Modular<T> &lhs, const Modular<T> &rhs) {
  return Modular<T>(lhs) *= rhs;
}
template <typename T, typename U>
Modular<T> operator*(const Modular<T> &lhs, U rhs) {
  return Modular<T>(lhs) *= rhs;
}
template <typename T, typename U>
Modular<T> operator*(U lhs, const Modular<T> &rhs) {
  return Modular<T>(lhs) *= rhs;
}

template <typename T>
Modular<T> operator/(const Modular<T> &lhs, const Modular<T> &rhs) {
  return Modular<T>(lhs) /= rhs;
}
template <typename T, typename U>
Modular<T> operator/(const Modular<T> &lhs, U rhs) {
  return Modular<T>(lhs) /= rhs;
}
template <typename T, typename U>
Modular<T> operator/(U lhs, const Modular<T> &rhs) {
  return Modular<T>(lhs) /= rhs;
}

template <typename T, typename U>
Modular<T> power(const Modular<T> &a, const U &b) {
  assert(b >= 0);
  Modular<T> x = a, res = 1;
  U p = b;
  while (p > 0) {
    if (p & 1)
      res *= x;
    x *= x;
    p >>= 1;
  }
  return res;
}

template <typename T> bool IsZero(const Modular<T> &number) {
  return number() == 0;
}

template <typename T> string to_string(const Modular<T> &number) {
  return to_string(number());
}

template <typename T>
std::ostream &operator<<(std::ostream &stream, const Modular<T> &number) {
  return stream << number();
}

template <typename T>
std::istream &operator>>(std::istream &stream, Modular<T> &number) {
  typename common_type<typename Modular<T>::Type, int64_t>::type x;
  stream >> x;
  number.value = Modular<T>::normalize(x);
  return stream;
}

// using ModType = int;

// struct VarMod { static ModType value; };
// ModType VarMod::value;
// ModType& md = VarMod::value;
// using Mint = Modular<VarMod>;

constexpr int md = 998244353;
using Mint = Modular<std::integral_constant<decay<decltype(md)>::type, md>>;

vector<Mint> fact(1, 1);
vector<Mint> inv_fact(1, 1);

Mint C(int n, int k) {
  if (k < 0 || k > n)
    return 0;
  while ((int)fact.size() < n + 1) {
    fact.emplace_back(fact.back() * (int)fact.size());
    inv_fact.emplace_back(1 / fact.back());
  }
  return fact[n] * inv_fact[k] * inv_fact[n - k];
}

// Mint C(int n, int k) {
//   Mint res = 1;
//   for (int i = 1; i <= k; i++) {
//     res = res * Mint(n - i + 1) / Mint(i);
//   }
//   return res;
// }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> l(k), r(k);
  for (int i = 0; i < k; i++) {
    cin >> l[i] >> r[i];
  }
  int mx = 2 * n;
  vector<Mint> dp(mx, 0);
  dp[0] = 1;
  dp[1] = -1;
  for (int i = 0; i < n; i++) {
    if (i > 0)
      dp[i] += dp[i - 1];
    for (int j = 0; j < k; j++) {
      dp[i + l[j]] += dp[i];
      dp[i + r[j] + 1] -= dp[i];
    }
  }
  cout << dp[n - 1] << '\\n';
  return 0;
}