#include <iostream>
#include <set>
#include <vector>
using namespace std;

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

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

#define DEBUG(x) cout << #x << ": " << (x) << endl
#define DEBUG_VEC(v)                                                           \\
  cerr << #v << ": ";                                                          \\
  REP(__i, (v).size()) cerr << ((v)[__i]) << ", ";                             \\
  cerr << endl
#define PRINT(x) cout << x << endl
#define all(x) x.begin(), x.end()
#define MM << " " <<
int main() {
  int N, K;
  cin >> N >> K;

  ll MOD = 998244353;

  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<ll> dp(N + 1, 0);
  dp[1] = 1;
  for (int i = 2; i <= N; i++) {
    for (const auto num : s) {
      if (i - num >= 1)
        dp[i] += dp[i - num] % MOD;
    }
  }

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

#include <iostream>
#include <set>
#include <vector>
using namespace std;

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

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

#define DEBUG(x) cout << #x << ": " << (x) << endl
#define DEBUG_VEC(v)                                                           \\
  cerr << #v << ": ";                                                          \\
  REP(__i, (v).size()) cerr << ((v)[__i]) << ", ";                             \\
  cerr << endl
#define PRINT(x) cout << x << endl
#define all(x) x.begin(), x.end()
#define MM << " " <<
int main() {
  int N, K;
  cin >> N >> K;

  ll MOD = 998244353;

  set<int> s;
  vector<int> L(K);
  vector<int> R(K);
  vector<ll> val(K);
  for (int i = 0; i < K; i++) {
    cin >> L[i] >> R[i];
  }

  vector<ll> dp(N + 1, 0);
  dp[1] = 1;
  for (int i = 2; i <= N; i++) {
    for (int k = 0; k < K; k++) {
      int l = L[k], r = R[k];
      if (i - l > 0)
        val[k] += dp[i - l] % MOD;
      if (i - r - 1 > 0)
        val[k] -= dp[i - r - 1] % MOD;
      dp[i] = (dp[i] + val[k]) % MOD;
    }
  }

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


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

const ll INF = 1LL << 62;
const double PI = acos(-1);
const double eps = 1e-10;

int main() {
  ll n, k, l, r;
  ll mod = 998244353;
  cin >> n >> k;
  vector<ll> vec;
  rep(i, k) {
    cin >> l >> r;
    for (ll i = l; i <= r; i++)
      vec.push_back(i);
  }
  sort(vec.begin(), vec.end());

  vector<ll> dp(n + 1, 0);
  dp[1] = 1;
  for (ll i = 1; i < n; i++) {
    if (dp[i] > 0) {
      for (auto d : vec) {
        if (i + d <= n) {
          dp[i + d] = (dp[i + d] + dp[i]) % mod;
        } else {
          break;
        }
      }
    }
  }
  // rep(i, n + 1) printf("%d%c", dp[i], (i == n ? '\\n' : ' '));
  cout << dp[n] << endl;
  return 0;
}

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

const ll INF = 1LL << 62;
const double PI = acos(-1);
const double eps = 1e-10;

// constexpr const int mod = 1000000007;
constexpr const int mod = 998244353;
class mint {
public:
  long long x;
  constexpr mint(long long x = 0) noexcept : x((x % mod + mod) % mod) {}
  constexpr int getmod() { return mod; }
  constexpr mint operator-() const noexcept { return mint(-x); }

  constexpr mint &operator+=(const mint &a) noexcept {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  constexpr mint &operator-=(const mint &a) noexcept {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  constexpr mint &operator*=(const mint &a) noexcept {
    (x *= a.x) %= mod;
    return *this;
  }
  constexpr mint &operator/=(const mint &a) noexcept {
    return (*this) *= a.inv();
  }

  constexpr mint operator+(const mint &a) const noexcept {
    return mint(*this) += a;
  }
  constexpr mint operator-(const mint &a) const noexcept {
    return mint(*this) -= a;
  }
  constexpr mint operator*(const mint &a) const noexcept {
    return mint(*this) *= a;
  }
  constexpr mint operator/(const mint &a) const noexcept {
    return mint(*this) /= a;
  }

  constexpr mint inv() const noexcept { return pow(mod - 2); }
  constexpr mint pow(long long t) const noexcept {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  friend istream &operator>>(istream &is, mint &a) noexcept {
    return is >> a.x;
  }
  friend ostream &operator<<(ostream &os, const mint &a) noexcept {
    return os << a.x;
  }
};

int main() {
  ll 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;
  return 0;
}


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

int main() {
  int64_t N, K;
  std::cin >> N >> K;
  std::vector<std::pair<int64_t, int64_t>> LR;

  for (size_t k = 0; k < K; ++k) {
    int64_t L, R;
    std::cin >> L >> R;
    LR.emplace_back(L, R);
  }

  std::vector<int64_t> V;
  V.resize(2 * 100000, 0);

  V[0] = 1;

  for (int64_t i = 1; i < N; ++i) {
    for (auto &lr : LR) {
      for (int64_t j = lr.first; j <= lr.second && i - j >= 0; ++j) {
        V[i] += V[i - j];
      }
    }
  }

  std::cout << (V[N - 1] % 998244353) << std::endl;

  return 0;
}

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

int main() {
  int64_t N, K;
  std::cin >> N >> K;
  std::vector<std::pair<int64_t, int64_t>> LR;

  for (size_t k = 0; k < K; ++k) {
    int64_t L, R;
    std::cin >> L >> R;
    LR.emplace_back(L, R);
  }

  std::vector<int64_t> V;
  V.resize(2 * 100000, 0);

  V[0] = 1;
  int64_t LRC[10];
  for (size_t i = 0; i < 10; ++i) {
    LRC[i] = 0;
  }

  for (int64_t i = 1; i < N; ++i) {
    for (int64_t j = 0; j < LR.size(); ++j) {
      if (i - LR[j].second - 1 >= 0) {
        LRC[j] -= V[i - LR[j].second - 1];
      }
      if (i - LR[j].first >= 0) {
        LRC[j] += V[i - LR[j].first];
      }
    }
    for (int64_t j = 0; j < LR.size(); ++j) {
      V[i] += LRC[j];
      V[i] %= 998244353;
    }
  }

  std::cout << (V[N - 1] % 998244353) << std::endl;

  return 0;
}


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

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 n, k;
int l[11], r[11];
mint dp[200005]; // マスNに行く方法
mint sum[200005];

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

  rep(i, k) { cin >> l[i] >> r[i]; }
  dp[1] = 1;
  sum[1] = 1;
  for (int i = 2; i <= n; i++) {
    mint cnt = 0;
    rep(j, k) {
      if (i - r[j] - 1 > 0) {
        cnt += sum[i - l[j]] - sum[i - r[j] - 1];
      } else {
        cnt += sum[i - l[j]];
      }
    }
    dp[i] = cnt;
    sum[i] = sum[i - 1] + cnt;
  }

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

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

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 n, k;
int l[11], r[11];
mint dp[200005]; // マスNに行く方法
mint sum[200005];

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

  rep(i, k) { cin >> l[i] >> r[i]; }
  dp[1] = 1;
  sum[1] = 1;
  for (int i = 2; i <= n; i++) {
    mint cnt = 0;
    rep(j, k) {
      if (i - r[j] - 1 > 0) {
        cnt += sum[i - l[j]] - sum[i - r[j] - 1];
      } else if (i - l[j] > 0) {
        cnt += sum[i - l[j]];
      }
    }
    dp[i] = cnt;
    sum[i] = sum[i - 1] + cnt;
  }

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


/*
    Author : Nishant Gupta 2.0
*/
#include <bits/stdc++.h>
using namespace std;

#define LL long long int
#define getcx getchar_unlocked
#define X first
#define Y second
#define PB push_back
#define MP make_pair
#define MAX 200005
#define LOG_MAX 20
#define MOD 998244353
#define INF 0x3f3f3f3f
#define INFL (LL(1e18))
#define chk(a) cerr << endl << #a << " : " << a << endl
#define chk2(a, b)                                                             \\
  cerr << endl << #a << " : " << a << "\\t" << #b << " : " << b << endl
#define chk3(a, b, c)                                                          \\
  cerr << endl                                                                 \\
       << #a << " : " << a << "\\t" << #b << " : " << b << "\\t" << #c << " : "  \\
       << c << endl
#define chk4(a, b, c, d)                                                       \\
  cerr << endl                                                                 \\
       << #a << " : " << a << "\\t" << #b << " : " << b << "\\t" << #c << " : "  \\
       << c << "\\t" << #d << " : " << d << endl
#define rep(i, a, n) for (i = a; i < n; i++)
#define rev(i, a, n) for (i = a; i >= n; i--)
#define in(x) scanf("%d", &x)
#define inl(x) scanf("%lld", &x)
#define in2(x, y) scanf("%d %d", &x, &y)
#define inl2(x, y) scanf("%lld %lld", &x, &y)
#define MSV(A, a) memset(A, a, sizeof(A))
#define rep_itr(itr, c) for (itr = (c).begin(); itr != (c).end(); itr++)
#define finish(x)                                                              \\
  {                                                                            \\
    cout << x << '\\n';                                                         \\
    return;                                                                    \\
  }
typedef pair<int, int> pi;
typedef pair<LL, LL> pl;
const char en = '\\n';

LL dp[MAX];
//~LL call(int pos, vector<int> &steps, int n) {
//~if(pos == n) return 1;
//~if(dp[pos] != -1) return dp[pos];

//~LL ans = 0;
//~for(int i=0;i<steps.size();i++) {
//~if(pos + steps[i] > n) break;
//~ans = ans + call(pos+steps[i], steps, n);
//~if(ans >= MOD) ans %= MOD;
//~}

//~return dp[pos] = ans;
//~}

void solve() {
  int n, k;
  in2(n, k);
  //~MSV(dp, -1);
  vector<pi> v;
  for (int i = 0; i < k; i++) {
    int l, r;
    in2(l, r);
    v.PB(MP(l, r));
  }

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

  dp[1] = 1;
  vector<LL> sum(MAX, 0);
  sum[1] = 1;
  for (int i = 2; i <= n; i++) {
    LL cnt = 0;
    for (int j = 0; j < k; j++) {
      LL temp = sum[i - v[j].X];
      temp = (temp - sum[i - v[j].Y - 1] + MOD) % MOD;
      cnt = (cnt + temp) % MOD;
    }
    dp[i] = cnt;
    sum[i] = (dp[i] + sum[i - 1]) % MOD;
  }

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

int main() {
  int t = 1;

  //~cin>>t;
  while (t--) {
    solve();
  }
  return 0;
}

/*
    Author : Nishant Gupta 2.0
*/
#include <bits/stdc++.h>
using namespace std;

#define LL long long int
#define getcx getchar_unlocked
#define X first
#define Y second
#define PB push_back
#define MP make_pair
#define MAX 200005
#define LOG_MAX 20
#define MOD 998244353
#define INF 0x3f3f3f3f
#define INFL (LL(1e18))
#define chk(a) cerr << endl << #a << " : " << a << endl
#define chk2(a, b)                                                             \\
  cerr << endl << #a << " : " << a << "\\t" << #b << " : " << b << endl
#define chk3(a, b, c)                                                          \\
  cerr << endl                                                                 \\
       << #a << " : " << a << "\\t" << #b << " : " << b << "\\t" << #c << " : "  \\
       << c << endl
#define chk4(a, b, c, d)                                                       \\
  cerr << endl                                                                 \\
       << #a << " : " << a << "\\t" << #b << " : " << b << "\\t" << #c << " : "  \\
       << c << "\\t" << #d << " : " << d << endl
#define rep(i, a, n) for (i = a; i < n; i++)
#define rev(i, a, n) for (i = a; i >= n; i--)
#define in(x) scanf("%d", &x)
#define inl(x) scanf("%lld", &x)
#define in2(x, y) scanf("%d %d", &x, &y)
#define inl2(x, y) scanf("%lld %lld", &x, &y)
#define MSV(A, a) memset(A, a, sizeof(A))
#define rep_itr(itr, c) for (itr = (c).begin(); itr != (c).end(); itr++)
#define finish(x)                                                              \\
  {                                                                            \\
    cout << x << '\\n';                                                         \\
    return;                                                                    \\
  }
typedef pair<int, int> pi;
typedef pair<LL, LL> pl;
const char en = '\\n';

LL dp[MAX];
//~LL call(int pos, vector<int> &steps, int n) {
//~if(pos == n) return 1;
//~if(dp[pos] != -1) return dp[pos];

//~LL ans = 0;
//~for(int i=0;i<steps.size();i++) {
//~if(pos + steps[i] > n) break;
//~ans = ans + call(pos+steps[i], steps, n);
//~if(ans >= MOD) ans %= MOD;
//~}

//~return dp[pos] = ans;
//~}

void solve() {
  int n, k;
  in2(n, k);
  vector<pi> v;
  for (int i = 0; i < k; i++) {
    int l, r;
    in2(l, r);
    v.PB(MP(l, r));
  }

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

  dp[1] = 1;
  vector<LL> sum(MAX, 0);
  sum[1] = 1;
  for (int i = 2; i <= n; i++) {
    LL cnt = 0;
    for (int j = 0; j < k; j++) {
      if (i - v[j].X <= 0)
        break;
      LL temp = sum[i - v[j].X];

      int st = max(0, i - v[j].Y - 1);
      temp = (temp - sum[st] + MOD) % MOD;
      cnt = (cnt + temp) % MOD;
    }
    dp[i] = cnt;
    sum[i] = (dp[i] + sum[i - 1]) % MOD;
  }

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

int main() {
  int t = 1;

  //~cin>>t;
  while (t--) {
    solve();
  }
  return 0;
}


#pragma GCC optimize("O2")
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wunused-label"
#pragma GCC diagnostic ignored "-Wsign-compare"

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

#define trav(a, A) for (auto &a : A)
#define f first
#define s second

typedef long long ll;

const ll MOD = 998244353;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;
const ll MAXN = 1e+5 + 7;

ll ft[MAXN];
void update(int i, ll v) {
  for (; i <= MAXN; i += i & -i)
    ft[i] += v, ft[i] %= MOD;
}

ll get(int i) {
  ll ans = 0;
  for (; i > 0; i -= i & -i)
    ans += ft[i], ans %= MOD;
  return ans;
}

void solve() {
  int n, k;
  cin >> n >> k;
  vector<pair<int, int>> seg(k);
  for (auto &a : seg)
    cin >> a.first >> a.second;
  sort(seg.begin(), seg.end());
  update(1, 1);
  for (int i = 2; i <= n; ++i) {
    for (int j = 0; j < k; ++j) {
      ll l = seg[j].f, r = seg[j].s;
      if (l > i)
        break;
      if (i >= l and i > r) {
        update(i, (get(i - l) - get(i - r - 1) + MOD) % MOD);
      } else if (i <= r and i > l)
        update(i, (get(i - l) + MOD) % MOD);
    }
  }
  cout << (get(n) - get(n - 1) + MOD) % MOD << '\\n';
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ll tc = 1; // cin >> tc;
  while (tc--) {
    solve();
  }

  return 0;
}

#pragma GCC optimize("O2")
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wunused-label"
#pragma GCC diagnostic ignored "-Wsign-compare"

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

#define trav(a, A) for (auto &a : A)
#define f first
#define s second

typedef long long ll;

const ll MOD = 998244353;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;
const ll MAXN = 2e+5 + 7;

ll ft[MAXN];
void update(int i, ll v) {
  for (; i <= MAXN; i += i & -i)
    ft[i] += v, ft[i] %= MOD;
}

ll get(int i) {
  ll ans = 0;
  for (; i > 0; i -= i & -i)
    ans += ft[i], ans %= MOD;
  return ans;
}

void solve() {
  int n, k;
  cin >> n >> k;
  vector<pair<int, int>> seg(k);
  for (auto &a : seg)
    cin >> a.first >> a.second;
  sort(seg.begin(), seg.end());
  update(1, 1);
  for (int i = 2; i <= n; ++i) {
    for (int j = 0; j < k; ++j) {
      ll l = seg[j].f, r = seg[j].s;
      if (l > i)
        break;
      if (i >= l and i > r) {
        update(i, (get(i - l) - get(i - r - 1) + MOD) % MOD);
      } else if (i <= r and i >= l)
        update(i, (get(i - l) + MOD) % MOD);
    }
  }
  cout << (get(n) - get(n - 1) + MOD) % MOD << '\\n';
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ll tc = 1; // cin >> tc;
  while (tc--) {
    solve();
  }

  return 0;
}


#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define rep(i, a, n) for (int i = (a); i < (n); i++)
#define per(i, a, n) for (int i = (a); i > (n); i--)
typedef long long ll;
const int maxn = 2e5 + 5;
const int mod = 998244353;
using namespace std;

ll dp[maxn], l[maxn], r[maxn], sum[maxn];

void solve() {
  ll n, k;
  cin >> n >> k;
  for (int i = 1; i <= k; i++) {
    cin >> l[i] >> r[i];
  }
  dp[1] = sum[1] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= k; j++) {
      dp[i] = (dp[i] + sum[i - l[j]] - sum[max(i - r[j] - 1, 0ll)]) % mod;
    }
    sum[i] = (dp[i] + sum[i - 1]) % mod;
  }
  cout << dp[n] << '\\n';
}

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
#ifdef DEBUG
  freopen("C:/Users/Fish_Brother/Desktop/in", "r", stdin);
  // freopen("C:/Users/Fish_Brother/Desktop/out", "w", stdout);
#endif

  // int t; cin >> t; while(t--)
  solve();

  return 0;
}

#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define rep(i, a, n) for (int i = (a); i < (n); i++)
#define per(i, a, n) for (int i = (a); i > (n); i--)
typedef long long ll;
const int maxn = 2e5 + 5;
const int mod = 998244353;
using namespace std;

ll dp[maxn], l[maxn], r[maxn], sum[maxn];

void solve() {
  ll n, k;
  cin >> n >> k;
  for (int i = 1; i <= k; i++) {
    cin >> l[i] >> r[i];
  }
  dp[1] = sum[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 1; j <= k; j++) {
      if (i > l[j])
        dp[i] =
            (dp[i] + sum[i - l[j]] - sum[max(i - r[j] - 1, 0ll)] + mod) % mod;
    }
    sum[i] = (dp[i] + sum[i - 1]) % mod;
  }
  cout << dp[n] << '\\n';
}

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
#ifdef DEBUG
  freopen("C:/Users/Fish_Brother/Desktop/in", "r", stdin);
  // freopen("C:/Users/Fish_Brother/Desktop/out", "w", stdout);
#endif

  // int t; cin >> t; while(t--)
  solve();

  return 0;
}


#include <bits/stdc++.h>
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp make_pair
#define sz(x) ((int)(x).size())
#define endl "\\n"
#define fastio                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(nullptr);
#define all(x) x.begin(), x.end()
#define y1 omg
#define INF 1000000010
#define FOR(x, n) for (int x = 0; x < n; x++)
#define ini(x, n) memset(x, n, sizeof(x));
#define MOD ((int)1e9 + 7)
#define atoi(x) ((x) - '0')
#define int ll
#define double long double
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;

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

const int MAX = 2e5, mod = 998244353;
int n, k, a, b, dp[MAX];
vi v;

int f(int x) {
  if (x > n)
    return 0;
  int &ret = dp[x];
  if (ret != -1)
    return ret;
  ret = 0;
  for (int i : v) {
    ret += f(x + i);
    ret %= mod;
  }
  return ret;
}

signed main() {
  fastio;
  ini(dp, -1);
  cin >> n >> k;
  FOR(i, k) {
    cin >> a >> b;
    for (int i = a; i <= b; i++)
      v.pb(i);
  }
  dp[n - 1] = 1;
  FOR(i, n) f(i);
  cout << f(0);
}

#include <bits/stdc++.h>
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp make_pair
#define sz(x) ((int)(x).size())
#define endl "\\n"
#define fastio                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(nullptr);
#define all(x) x.begin(), x.end()
#define y1 omg
#define INF 1000000010
#define FOR(x, n) for (int x = 0; x < n; x++)
#define ini(x, n) memset(x, n, sizeof(x));
#define MOD ((int)1e9 + 7)
#define atoi(x) ((x) - '0')
#define int ll
#define double long double
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;

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

const int MAX = 2e5, mod = 998244353;
int n, k, a, b, dp[MAX], sum[MAX];
vii v;

int getSum(int a, int b) {
  if (b < 0)
    return 0;
  a = max(a, 0LL);
  if (a == 0)
    return sum[b];
  return (sum[b] - sum[a - 1]) % mod;
}

signed main() {
  fastio;
  cin >> n >> k;
  FOR(i, k) {
    cin >> a >> b;
    v.pb(mp(a, b));
  }
  dp[0] = sum[0] = 1;
  for (int i = 1; i < n; i++) {
    FOR(j, k) {
      dp[i] += getSum(i - v[j].se, i - v[j].fi);
      dp[i] %= mod;
    }
    sum[i] = (sum[i - 1] + dp[i]) % mod;
  }
  cout << (dp[n - 1] % mod + mod) % mod;
}


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

using namespace std;
using LL = long long;
using P = pair<int, int>;
const LL mod = 998244353;

int main() {
  LL N, K;
  cin >> N >> K;
  vector<LL> L(K), R(K);
  rep(i, K) cin >> L[i] >> R[i];
  vector<LL> dp(N + 1), num(K);
  dp[1] = 1;
  for (int i = 2; i <= N; i++) {
    rep(j, K) {
      if (R[j] < i) {
        num[j] += dp[i - L[j]];
        num[j] -= dp[i - R[j] - 1];
        dp[i] += num[j];
      } else if (L[j] < i) {
        num[j] += dp[i - L[j]];
        for (int k = 1; k <= i - L[j]; k++)
          dp[i] += dp[k];
      }
      dp[i] %= mod;
    }
  }
  LL ans = dp[N];
  while (ans < 0)
    ans += mod;
  cout << ans << endl;

  return 0;
}

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

using namespace std;
using LL = long long;
using P = pair<int, int>;
const LL mod = 998244353;

int main() {
  LL N, K;
  cin >> N >> K;
  vector<LL> L(K), R(K);
  rep(i, K) cin >> L[i] >> R[i];
  vector<LL> dp(N + 1), num(K), sum(N + 1);
  dp[1] = 1, sum[1] = 1;
  for (int i = 2; i <= N; i++) {
    rep(j, K) {
      if (R[j] < i) {
        num[j] += dp[i - L[j]];
        num[j] -= dp[i - R[j] - 1];
        dp[i] += num[j];
      } else if (L[j] < i) {
        num[j] += dp[i - L[j]];
        dp[i] += sum[i - L[j]];
      }
      dp[i] %= mod;
      sum[i] = (sum[i - 1] + dp[i]);
      sum[i] %= mod;
    }
  }
  LL ans = dp[N];
  while (ans < 0)
    ans += mod;
  cout << ans << endl;

  return 0;
}


#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define codefor                                                                \\
  int test;                                                                    \\
  scanf("%d", &test);                                                          \\
  while (test--)
#define INT(...)                                                               \\
  int __VA_ARGS__;                                                             \\
  in(__VA_ARGS__)
#define LL(...)                                                                \\
  ll __VA_ARGS__;                                                              \\
  in(__VA_ARGS__)
#define yn(ans)                                                                \\
  if (ans)                                                                     \\
    printf("Yes\\n");                                                           \\
  else                                                                         \\
    printf("No\\n")
#define YN(ans)                                                                \\
  if (ans)                                                                     \\
    printf("YES\\n");                                                           \\
  else                                                                         \\
    printf("NO\\n")
#define vector1d(type, name, ...) vector<type> name(__VA_ARGS__)
#define vector2d(type, name, h, ...)                                           \\
  vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD = 998244353;
// 入力系
void scan(int &a) { scanf("%d", &a); }
void scan(long long &a) { scanf("%lld", &a); }
template <class T> void scan(T &a) { cin >> a; }
template <class T> void scan(vector<T> &vec) {
  for (auto &&it : vec)
    scan(it);
}
void in() {}
template <class Head, class... Tail> void in(Head &head, Tail &...tail) {
  scan(head);
  in(tail...);
}
// 出力系
void print(const int &a) { printf("%d", a); }
void print(const long long &a) { printf("%lld", a); }
void print(const double &a) { printf("%.15lf", a); }
template <class T> void print(const T &a) { cout << a; }
template <class T> void print(const vector<T> &vec) {
  if (vec.empty())
    return;
  print(vec[0]);
  for (auto it = vec.begin(); ++it != vec.end();) {
    putchar(' ');
    print(*it);
  }
}
void out() { putchar('\\n'); }
template <class T> void out(const T &t) {
  print(t);
  putchar('\\n');
}
template <class Head, class... Tail>
void out(const Head &head, const Tail &...tail) {
  print(head);
  putchar(' ');
  out(tail...);
}
// デバッグ系
template <class T> void dprint(const T &a) { cerr << a; }
template <class T> void dprint(const vector<T> &vec) {
  if (vec.empty())
    return;
  cerr << vec[0];
  for (auto it = vec.begin(); ++it != vec.end();) {
    cerr << " " << *it;
  }
}
void debug() { cerr << endl; }
template <class T> void debug(const T &t) {
  dprint(t);
  cerr << endl;
}
template <class Head, class... Tail>
void debug(const Head &head, const Tail &...tail) {
  dprint(head);
  cerr << " ";
  debug(tail...);
}
ll intpow(ll a, ll b) {
  ll ans = 1;
  while (b) {
    if (b & 1)
      ans *= a;
    a *= a;
    b /= 2;
  }
  return ans;
}
ll modpow(ll a, ll b, ll p) {
  ll ans = 1;
  while (b) {
    if (b & 1)
      (ans *= a) %= p;
    (a *= a) %= p;
    b /= 2;
  }
  return ans;
}
ll updivide(ll a, ll b) {
  if (b == 1)
    return a;
  else if (a % b == 0)
    return a / b;
  else
    return (a / b) + 1;
}

int main() {
  INT(n, k);
  vector<int> step;
  int l, r;
  rep(i, k) {
    in(l, r);
    for (int j = l; j <= r; j++) {
      step.push_back(j);
    }
  }
  // debug(step);
  sort(all(step));
  vector<ll> dp(n + 1, 0);
  dp[1] = 1;
  for (int i = 1; i <= n; i++) {
    if (dp[i] == 0)
      continue;
    for (int j = 0; j < step.size(); j++) {
      if (i + step[j] <= n) {
        dp[i + step[j]] += dp[i];
        dp[i + step[j]] %= MOD;
      } else {
        step.erase(step.begin() + j);
        j--;
      }
    }
  }
  out(dp[n]);
}

#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define codefor                                                                \\
  int test;                                                                    \\
  scanf("%d", &test);                                                          \\
  while (test--)
#define INT(...)                                                               \\
  int __VA_ARGS__;                                                             \\
  in(__VA_ARGS__)
#define LL(...)                                                                \\
  ll __VA_ARGS__;                                                              \\
  in(__VA_ARGS__)
#define yn(ans)                                                                \\
  if (ans)                                                                     \\
    printf("Yes\\n");                                                           \\
  else                                                                         \\
    printf("No\\n")
#define YN(ans)                                                                \\
  if (ans)                                                                     \\
    printf("YES\\n");                                                           \\
  else                                                                         \\
    printf("NO\\n")
#define vector1d(type, name, ...) vector<type> name(__VA_ARGS__)
#define vector2d(type, name, h, ...)                                           \\
  vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD = 998244353;
// 入力系
void scan(int &a) { scanf("%d", &a); }
void scan(long long &a) { scanf("%lld", &a); }
template <class T> void scan(T &a) { cin >> a; }
template <class T> void scan(vector<T> &vec) {
  for (auto &&it : vec)
    scan(it);
}
void in() {}
template <class Head, class... Tail> void in(Head &head, Tail &...tail) {
  scan(head);
  in(tail...);
}
// 出力系
void print(const int &a) { printf("%d", a); }
void print(const long long &a) { printf("%lld", a); }
void print(const double &a) { printf("%.15lf", a); }
template <class T> void print(const T &a) { cout << a; }
template <class T> void print(const vector<T> &vec) {
  if (vec.empty())
    return;
  print(vec[0]);
  for (auto it = vec.begin(); ++it != vec.end();) {
    putchar(' ');
    print(*it);
  }
}
void out() { putchar('\\n'); }
template <class T> void out(const T &t) {
  print(t);
  putchar('\\n');
}
template <class Head, class... Tail>
void out(const Head &head, const Tail &...tail) {
  print(head);
  putchar(' ');
  out(tail...);
}
// デバッグ系
template <class T> void dprint(const T &a) { cerr << a; }
template <class T> void dprint(const vector<T> &vec) {
  if (vec.empty())
    return;
  cerr << vec[0];
  for (auto it = vec.begin(); ++it != vec.end();) {
    cerr << " " << *it;
  }
}
void debug() { cerr << endl; }
template <class T> void debug(const T &t) {
  dprint(t);
  cerr << endl;
}
template <class Head, class... Tail>
void debug(const Head &head, const Tail &...tail) {
  dprint(head);
  cerr << " ";
  debug(tail...);
}
ll intpow(ll a, ll b) {
  ll ans = 1;
  while (b) {
    if (b & 1)
      ans *= a;
    a *= a;
    b /= 2;
  }
  return ans;
}
ll modpow(ll a, ll b, ll p) {
  ll ans = 1;
  while (b) {
    if (b & 1)
      (ans *= a) %= p;
    (a *= a) %= p;
    b /= 2;
  }
  return ans;
}
ll updivide(ll a, ll b) {
  if (b == 1)
    return a;
  else if (a % b == 0)
    return a / b;
  else
    return (a / b) + 1;
}

int main() {
  INT(n, k);
  vector<pair<int, int>> step(k);
  int l, r;
  rep(i, k) {
    in(l, r);
    step[i] = make_pair(l, r);
  }
  sort(all(step));
  vector<ll> dp(n + 1, 0), dpsum(n + 1, 0);
  dp[1] = 1;
  dpsum[1] = 1;
  int left, right;
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < k; j++) {
      left = max(i - step[j].second - 1, 0);
      right = max(i - step[j].first, 0);
      dp[i] += dpsum[right] - dpsum[left];
      if (dp[i] < 0)
        dp[i] += MOD;
      else
        dp[i] %= MOD;
    }
    dpsum[i] = dpsum[i - 1] + dp[i];
    dpsum[i] %= MOD;
  }
  out(dp[n]);
}


#include "bits/stdc++.h"

#define MOD 998244353
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define FOR(i, j, k) for (ll i = j; i < k; i++)
#define debug_print(var) cerr << #var << "=" << var << endl;
#define DUMP(i, v)                                                             \\
  for (ll i = 0; i < v.size(); i++)                                            \\
  cerr << v[i] << " "
#define fi first
#define se second

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct edge {
  ll x, c;
};

ll mod(ll a, ll mod) {
  ll res = a % mod;
  if (res < 0)
    res = res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

ll modinv(ll a, ll mod) {
  ll b = mod, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= mod;
  if (u < 0)
    u += mod;
  return u;
}

ll gcd(ll a, ll b) {
  ll r = a % b;
  if (r == 0)
    return b;
  else
    return gcd(b, a % b);
}

bool is_prime(ll n) {
  ll i = 2;
  if (n == 1)
    return false;
  if (n == 2)
    return true;
  bool res = true;
  while (i * i < n) {
    if (n % i == 0) {
      res = false;
    }
    i = i + 1;
  }

  // if(i==1)res = false;
  if (n % i == 0)
    res = false;
  return res;
}
/**************************************
** A main function starts from here  **
***************************************/
int main() {
  ll N, K;
  cin >> N >> K;
  llvec L(K), R(K);
  rep(i, K) { cin >> L[i] >> R[i]; }
  llvec dp(N, 0);
  llvec a(N, 0);
  dp[0] = 1;
  rep(i, N) {
    if (i > 0)
      a[i] = mod(a[i] + a[i - 1], MOD);
    dp[i] = mod(dp[i] + a[i], MOD);
    rep(j, K) {
      if (L[j] + 1 < N)
        a[i + L[j]] = mod(a[i + L[j]] + dp[i], MOD);
      if (i + R[j] + 1 < N)
        a[i + R[j] + 1] = mod(a[i + R[j] + 1] - dp[i], MOD);
    }
  }
  cout << dp[N - 1];
  return 0;
}

#include "bits/stdc++.h"

#define MOD 998244353
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define FOR(i, j, k) for (ll i = j; i < k; i++)
#define debug_print(var) cerr << #var << "=" << var << endl;
#define DUMP(i, v)                                                             \\
  for (ll i = 0; i < v.size(); i++)                                            \\
  cerr << v[i] << " "
#define fi first
#define se second

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct edge {
  ll x, c;
};

ll mod(ll a, ll mod) {
  ll res = a % mod;
  if (res < 0)
    res = res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

ll modinv(ll a, ll mod) {
  ll b = mod, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= mod;
  if (u < 0)
    u += mod;
  return u;
}

ll gcd(ll a, ll b) {
  ll r = a % b;
  if (r == 0)
    return b;
  else
    return gcd(b, a % b);
}

bool is_prime(ll n) {
  ll i = 2;
  if (n == 1)
    return false;
  if (n == 2)
    return true;
  bool res = true;
  while (i * i < n) {
    if (n % i == 0) {
      res = false;
    }
    i = i + 1;
  }

  // if(i==1)res = false;
  if (n % i == 0)
    res = false;
  return res;
}
/**************************************
** A main function starts from here  **
***************************************/
int main() {
  ll N, K;
  cin >> N >> K;
  llvec L(K), R(K);
  rep(i, K) { cin >> L[i] >> R[i]; }
  llvec dp(N, 0);
  llvec a(N, 0);
  dp[0] = 1;
  rep(i, N) {
    if (i > 0)
      a[i] = mod(a[i] + a[i - 1], MOD);
    dp[i] = mod(dp[i] + a[i], MOD);
    rep(j, K) {
      if (L[j] + i < N)
        a[i + L[j]] = mod(a[i + L[j]] + dp[i], MOD);
      if (i + R[j] + 1 < N)
        a[i + R[j] + 1] = mod(a[i + R[j] + 1] - dp[i], MOD);
    }
  }
  cout << dp[N - 1];
  return 0;
}


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

int main() {
  int n, k;
  cin >> n >> k;
  vector<ll> vec, dp(n, 0);
  rep(i, k) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++) {
      vec.push_back(j);
    }
  }
  dp[0] = 1;
  rep(i, n) {
    for (auto x : vec) {
      if (i - x >= 0) {
        dp[i] += dp[i - x];
        dp[i] %= 998244353;
      }
    }
  }
  cout << dp[n - 1] << endl;
}

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

int main() {
  const int mod = 998244353;
  int n, k;
  cin >> n >> k;
  vector<int> dp(n + 1, 0), rui(n + 1), l(k), r(k);
  rep(i, k) { cin >> l[i] >> r[i]; }
  dp[1] = 1;
  rui[0] = 0;
  rui[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] += rui[ri] - rui[li - 1];
      dp[i] %= mod;
      dp[i] = (dp[i] + mod) % mod;
    }
    rui[i] = rui[i - 1] + dp[i];
    rui[i] %= mod;
  }
  cout << (dp[n] + mod) % mod << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\\n"
#define si(a) scanf("%d", &a)
#define si2(a, b) scanf("%d%d", &a, &b)
#define sl(a) scanf("%lld", &a)
#define sl2(a, b) scanf("%lld%lld", &a, &b)
#define pb push_back
#define mk make_pair
#define loop(n) for (int i = 0; i < n; i++)
#define FOR(a, b) for (int i = a; i <= b; i++)
#define sz size()
#define ff first
#define ss second
#define mem(a, val) memset(a, val, sizeof(a))
#define md 998244353
#define pi acos(-1.0)

ll p[100];
map<ll, ll> m;
map<vector<ll>, ll> mp;
vector<ll> v, vp, vv, vk;
ll ans = 0;
void solve(int s, ll n) {
  if (n < 0)
    return;
  if (n == 0) {
    vp = vv;

    sort(vp.begin(), vp.end());
    if (mp[vp] == 0) {
      int cnt = 0;
      if (vv.sz > 1)
        for (int i = 1; i < vv.sz; i++) {
          if (vv[i] == vv[i - 1])
            cnt++;
          else {
            if (cnt > 1)
              vk.pb(cnt);
            cnt = 0;
          }
        }
      if (vv[0] == vv[vv.size() - 1]) {
        ans++;
        ans %= md;
      } else {
        ans += p[vv.size()];
        ans %= md;
      }

      for (int i = 0; i < vk.sz; i++)
        ans %= vk[i];
      ans %= md;
      mp[vp] = 1;
    }
    return;
  }

  for (int i = s; i < v.size(); i++) {
    vv.pb(v[i]);
    solve(i, n - v[i]);
    vv.pop_back();
  }
}

int main() {
  ll a, b, t, n, i, j, k, l, mn = 0, mx = 0;

  p[0] = 1;
  for (int i = 1; i <= 22; i++)
    p[i] = p[i - 1] * i;

  sl2(n, k);
  for (int i = 0; i < k; i++) {
    cin >> a;
    if (m[a] == 0)
      v.pb(a), m[a] = 1;
    cin >> a;
    if (m[a] == 0)
      v.pb(a), m[a] = 1;
  }

  // for(int i=0; i<v.sz; i++)
  // cout<<v[i]<<" ";

  solve(0, n - 1);

  cout << ans;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\\n"
#define si(a) scanf("%d", &a)
#define si2(a, b) scanf("%d%d", &a, &b)
#define sl(a) scanf("%lld", &a)
#define sl2(a, b) scanf("%lld%lld", &a, &b)
#define pb push_back
#define mk make_pair
#define loop(n) for (int i = 0; i < n; i++)
#define FOR(a, b) for (int i = a; i <= b; i++)
#define sz size()
#define ff first
#define ss second
#define mem(a, val) memset(a, val, sizeof(a))
#define md 998244353
#define pi acos(-1.0)

ll f[200010], sum[200010], l[20], r[20];
int main() {
  ll t, n, i, j, k, lf, rt;
  sl2(n, k);
  for (int i = 0; i < k; i++) {
    sl2(l[i], r[i]);
  }
  sum[1] = f[1] = 1;
  for (int j = 2; j <= n; j++) {
    for (int i = 0; i < k; i++) {
      lf = max(1LL, j - r[i]);
      rt = j - l[i];
      if (rt < 1)
        continue;
      f[j] = ((f[j] + sum[rt] - sum[lf - 1]) % md + md) % md;
    }
    sum[j] = (sum[j - 1] + f[j]) % md;
  }
  cout << f[n]; //%md;
}


#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPP(i, n) for (int i = 1; i <= n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
// const double PI = acos(-1);
// const double EPS = 1e-15;
// long long INF=(long long)1E17;
// #define i_7 (long long)(1e9+7)
#define i_7 998'244'353
long mod(long a) {
  long long c = a % i_7;
  if (c >= 0)
    return c;
  return c + i_7;
}
long long po(long a, long b) {
  if (b == 0) {
    return 1;
  }

  long long z = po(a, b / 2);
  z = mod(z * z);
  if (b % 2 != 0) {
    z = mod(a * z);
  }
  return z;
}

bool prime_(int n) {
  if (n == 1) {
    return false;
  } else if (n == 2) {
    return true;
  } else {
    for (int i = 2; i <= std::sqrt(n); i++) {
      if (n % i == 0) {
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b) {
  if (a < b) {
    std::swap(a, b);
  }
  if (a % b == 0) {
    return b;
  } else {
    return gcd_(b, a % b);
  }
}

long long lcm_(long long x, long long y) { return (x / gcd_(x, y)) * y; }

using namespace std;
// using namespace boost::multiprecision;
// using namespace __gnu_pbds;

int n, k;
int l[10], r[10];
long long dp[200'010];
typedef pair<int, int> P;
map<P, long long> mp;

long long dfs(int pos) {
  if (pos == 0)
    return 1;
  if (dp[pos] >= 0)
    return dp[pos];
  long long res = 0;
  for (int i = 0; i < k; i++) {
    if (l[i] > pos)
      break;
    int st = pos - min(pos, r[i]);
    int ed = pos - l[i];
    P p = P(st, ed);
    if (mp.find(p) != mp.end()) {
      res += mp[p];
      res = mod(res);
      continue;
    }
    long long temp = 0;
    for (int prev = ed; prev >= st; prev--) {
      P q = P(st, prev);
      if (mp.find(q) != mp.end()) {
        temp += mp[q];
        temp = mod(temp);
        break;
      }
      temp += dfs(prev);
      temp = mod(temp);
    }
    mp[p] = temp;
    res += temp;
    res = mod(res);
  }
  return dp[pos] = res;
}

int main() {
  using namespace std;
  cin >> n >> k;
  REP(i, k) cin >> l[i] >> r[i];

  vector<P> vec;
  REP(i, k) vec.push_back(P(l[i], r[i]));
  sort(ALL(vec));
  REP(i, k) {
    l[i] = vec[i].first;
    r[i] = vec[i].second;
  }
  REP(i, n) dp[i] = -1;
  long long ans = dfs(n - 1);
  cout << ans << endl;
  return 0;
}

#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPP(i, n) for (int i = 1; i <= n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
// const double PI = acos(-1);
// const double EPS = 1e-15;
// long long INF=(long long)1E17;
// #define i_7 (long long)(1e9+7)
#define i_7 998'244'353
long mod(long a) {
  long long c = a % i_7;
  if (c >= 0)
    return c;
  return c + i_7;
}
long long po(long a, long b) {
  if (b == 0) {
    return 1;
  }

  long long z = po(a, b / 2);
  z = mod(z * z);
  if (b % 2 != 0) {
    z = mod(a * z);
  }
  return z;
}

bool prime_(int n) {
  if (n == 1) {
    return false;
  } else if (n == 2) {
    return true;
  } else {
    for (int i = 2; i <= std::sqrt(n); i++) {
      if (n % i == 0) {
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b) {
  if (a < b) {
    std::swap(a, b);
  }
  if (a % b == 0) {
    return b;
  } else {
    return gcd_(b, a % b);
  }
}

long long lcm_(long long x, long long y) { return (x / gcd_(x, y)) * y; }

using namespace std;
// using namespace boost::multiprecision;
// using namespace __gnu_pbds;

template <typename T> class SegmentTree {
  using F = function<T(T, T)>;
  int n;
  F f;
  T t;
  vector<T> dat;

public:
  SegmentTree(F f, T t) : f(f), t(t) {}
  void init(int n_) {
    n = 1;
    while (n < n_)
      n <<= 1;
    dat.assign(n << 1, t);
  }
  void build(const vector<T> &v) {
    auto n_ = (int)v.size();
    init(n_);
    for (int i = 0; i < n_; i++)
      dat[n + i] = v[i];
    for (int i = n - 1; i > 0; i--)
      dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]);
  }
  // k番目の値をxに変更する。
  void set_val(int k, T x) {
    dat[k += n] = x;
    while (k >>= 1)
      dat[k] = f(dat[(k << 1) | 0], dat[(k << 1) | 1]);
  }
  //[a,b)に対してfを適用する。
  T query(int a, int b) {
    T vl = t, vr = t;
    for (int l = a + n, r = b + n; l < r; l >>= 1, r >>= 1) {
      if (l & 1)
        vl = f(vl, dat[l++]);
      if (r & 1)
        vr = f(dat[--r], vr);
    }
    return f(vl, vr);
  }
};

int n, k;
int l[10], r[10];
long long dp[200'010];

int main() {
  using namespace std;
  cin >> n >> k;
  REP(i, k) cin >> l[i] >> r[i];
  typedef pair<int, int> P;
  vector<P> vec;
  REP(i, k) vec.push_back(P(l[i], r[i]));
  sort(ALL(vec));
  REP(i, k) {
    l[i] = vec[i].first;
    r[i] = vec[i].second;
  }
  REP(i, n) dp[i] = -1;

  auto f = [](long long a, long long b) { return mod(a + b); };
  SegmentTree<long long> seg(f, 0LL);
  seg.build(vector<long long>(n, 0LL));

  seg.set_val(0, 1);
  for (int pos = 1; pos < n; pos++) {
    long long res = 0;
    for (int i = 0; i < k; i++) {
      if (l[i] > pos)
        break;
      int st = pos - min(pos, r[i]);
      int ed = pos - l[i];
      res += seg.query(st, ed + 1);
      res = mod(res);
    }
    seg.set_val(pos, res);
  }
  long long ans = seg.query(n - 1, n);
  cout << ans << endl;
  return 0;
}


/*/ Author: KaySeeKay /*/

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

/*/---------------------------Defines-----------------------------------------/*/

#pragma GCC optimize("Ofast")
#define int long long
#define IOS                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
#define pb push_back
#define eb emplace_back
#define fn for (int i = 0; i < n; i++)
#define fn1 for (int i = 1; i <= n; i++)
#define fm for (int j = 0; j < m; j++)
#define fm1 for (int j = 1; j <= m; j++)
#define fi first
#define se second
#define endl '\\n'
#define PI 3.14159265358979323846
#define MOD 998244353
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
const int N = 2e6 + 5;
const int INF = 1e18L;
// mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
/*/-----------------------------Debug
 * begins----------------------------------/*/
vector<string> split(const string &s, char c) {
  vector<string> v;
  stringstream ss(s);
  string x;
  while (getline(ss, x, c))
    v.emplace_back(x);
  return move(v);
}
template <typename T, typename... Args> inline string arrStr(T arr, int n) {
  stringstream s;
  s << "[";
  for (int i = 0; i < n - 1; i++)
    s << arr[i] << ",";
  if (n > 0)
    s << arr[n - 1];
  s << "]";
  return s.str();
}
#define trace(args...)                                                         \\
  {                                                                            \\
    __trace_begin(__LINE__);                                                   \\
    __trace(split(#args, ',').begin(), args);                                  \\
  }
inline void __trace_begin(int line) { cerr << "#" << line << ": "; }
template <typename T> inline void __trace_out_var(vector<T> val) {
  cerr << arrStr(val, val.size());
}
template <typename T> inline void __trace_out_var(T *val) {
  cerr << arrStr(val, 10);
}
template <typename T> inline void __trace_out_var(T val) { cerr << val; }
inline void __trace(vector<string>::iterator it) { cerr << endl; }

template <typename T, typename... Args>
inline void __trace(vector<string>::iterator it, T a, Args... args) {
  cerr << it->substr((*it)[0] == ' ', it->length()) << "=";
  __trace_out_var(a);
  cerr << "; ";
  __trace(++it, args...);
}
/*/-----------------------------Code begins----------------------------------/*/
int ar[N];
inline int add(int x, int y, int mod) {
  if (y >= mod)
    y %= mod;
  if (x >= mod)
    x %= mod;
  x += y;
  return (x >= mod ? x - mod : x);
}
inline int sub(int x, int y, int mod) {
  x -= y;
  if (x + mod <= 0) {
    x %= mod;
  }
  return (x < 0 ? x + mod : x);
}
signed main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  IOS;
  int T = 1;
  // cin >> T;
  while (T--) {
    int n, m;
    cin >> n >> m;
    vector<int> dp(2 * n + 1);
    vector<pair<int, int>> v(m);
    fm {
      int x, y;
      cin >> v[j].fi >> v[j].se;
    }
    sort(all(v));
    int ans;
    dp[1] = 1;
    dp[2] = MOD - 1;
    for (int i = 1; i <= n; i++) {
      dp[i + 1] += dp[i];
      dp[i] %= MOD;
      fm {
        int l = v[j].fi;
        int r = v[j].se;
        dp[i + l] += dp[i];
        dp[i + r + 1] -= dp[i];
      }
    }
    ans = dp[n];
    cout << ans;
  }
  return 0;
}

/*/ Author: KaySeeKay /*/

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

/*/---------------------------Defines-----------------------------------------/*/

#pragma GCC optimize("Ofast")
#define int long long
#define IOS                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
#define pb push_back
#define eb emplace_back
#define fn for (int i = 0; i < n; i++)
#define fn1 for (int i = 1; i <= n; i++)
#define fm for (int j = 0; j < m; j++)
#define fm1 for (int j = 1; j <= m; j++)
#define fi first
#define se second
#define endl '\\n'
#define PI 3.14159265358979323846
#define MOD 998244353
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
const int N = 2e6 + 5;
const int INF = 1e18L;
// mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
/*/-----------------------------Debug
 * begins----------------------------------/*/
vector<string> split(const string &s, char c) {
  vector<string> v;
  stringstream ss(s);
  string x;
  while (getline(ss, x, c))
    v.emplace_back(x);
  return move(v);
}
template <typename T, typename... Args> inline string arrStr(T arr, int n) {
  stringstream s;
  s << "[";
  for (int i = 0; i < n - 1; i++)
    s << arr[i] << ",";
  if (n > 0)
    s << arr[n - 1];
  s << "]";
  return s.str();
}
#define trace(args...)                                                         \\
  {                                                                            \\
    __trace_begin(__LINE__);                                                   \\
    __trace(split(#args, ',').begin(), args);                                  \\
  }
inline void __trace_begin(int line) { cerr << "#" << line << ": "; }
template <typename T> inline void __trace_out_var(vector<T> val) {
  cerr << arrStr(val, val.size());
}
template <typename T> inline void __trace_out_var(T *val) {
  cerr << arrStr(val, 10);
}
template <typename T> inline void __trace_out_var(T val) { cerr << val; }
inline void __trace(vector<string>::iterator it) { cerr << endl; }

template <typename T, typename... Args>
inline void __trace(vector<string>::iterator it, T a, Args... args) {
  cerr << it->substr((*it)[0] == ' ', it->length()) << "=";
  __trace_out_var(a);
  cerr << "; ";
  __trace(++it, args...);
}
/*/-----------------------------Code begins----------------------------------/*/
int ar[N];
inline int add(int x, int y, int mod) {
  if (y >= mod)
    y %= mod;
  if (x >= mod)
    x %= mod;
  x += y;
  return (x >= mod ? x - mod : x);
}
inline int sub(int x, int y, int mod) {
  x -= y;
  if (x + mod <= 0) {
    x %= mod;
  }
  return (x < 0 ? x + mod : x);
}
int dp[N];
signed main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  IOS;
  int T = 1;
  // cin >> T;
  while (T--) {
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> v(m);
    fm {
      int x, y;
      cin >> v[j].fi >> v[j].se;
    }
    sort(all(v));
    int ans;
    dp[1] = 1;
    dp[2] = MOD - 1;
    for (int i = 1; i <= n; i++) {
      dp[i + 1] += dp[i];
      dp[i] %= MOD;
      fm {
        int l = v[j].fi;
        int r = v[j].se;
        dp[i + l] += dp[i];
        dp[i + r + 1] -= dp[i];
      }
    }
    ans = dp[n];
    cout << ans;
  }
  return 0;
}

terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc


#include <bits/stdc++.h>
using namespace std;
#define fast_io                                                                \\
  cin.tie(0);                                                                  \\
  ios_base::sync_with_stdio(0);
string to_string(string s) { return '"' + s + '"'; }
string to_string(char s) { return string(1, s); }
string to_string(const char *s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A> string to_string(A);
template <typename A, typename B> string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A> string to_string(A v) {
  bool f = 1;
  string r = "{";
  for (const auto &x : v) {
    if (!f)
      r += ", ";
    f = 0;
    r += to_string(x);
  }
  return r + "}";
}
void debug_out() { cout << endl; }
void show() { cout << endl; }
void pret() {
  cout << endl;
  exit(0);
}
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
  cout << " " << to_string(H);
  debug_out(T...);
}
template <typename Head, typename... Tail> void show(Head H, Tail... T) {
  cout << H << " ";
  show(T...);
}
template <typename Head, typename... Tail> void pret(Head H, Tail... T) {
  cout << H << " ";
  pret(T...);
}
#define pr(...) cout << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
typedef long long ll;
#define int ll
typedef long double ld;
typedef vector<int> vi;
#define disp(x) cout << x << " ";
#define rep(i, a, b) for (int i = a; i < (int)b; i++)
#define fo(i, a, b) for (int i = a; i <= (int)b; i++)
#define rf(i, a, b) for (int i = a; i >= (int)b; i--)
#define mp make_pair
#define pb emplace_back
#define F first
#define S second
#define endl '\\n'
// cout.setf(ios::fixed);cout.precision(18)
const int MOD = 998244353;
const int maxn = 3e5 + 10;

int dp[maxn];

void add(int l, int r, int x) {
  dp[l] += x;
  dp[l] %= MOD;
  if (r >= maxn)
    return;
  dp[r + 1] -= x;
  dp[r + 1] %= MOD;
}

int32_t main() {
  fast_io;
  int n, k;
  cin >> n >> k;
  vector<pair<int, int>> v;
  for (int i = 0; i < k; ++i) {
    int l, r;
    cin >> l >> r;
    v.emplace_back(l, r);
  }
  add(1, 1, 1);
  fo(i, 1, n) {
    dp[i] += dp[i - 1];
    dp[i] %= MOD;
    // show(i, dp[i]);
    for (const auto &it : v) {
      add(i + it.first, i + it.second, dp[i]);
    }
  }
  if (dp[n] < 0)
    dp[n] += MOD;
  show(dp[n]);
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define fast_io                                                                \\
  cin.tie(0);                                                                  \\
  ios_base::sync_with_stdio(0);
string to_string(string s) { return '"' + s + '"'; }
string to_string(char s) { return string(1, s); }
string to_string(const char *s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A> string to_string(A);
template <typename A, typename B> string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A> string to_string(A v) {
  bool f = 1;
  string r = "{";
  for (const auto &x : v) {
    if (!f)
      r += ", ";
    f = 0;
    r += to_string(x);
  }
  return r + "}";
}
void debug_out() { cout << endl; }
void show() { cout << endl; }
void pret() {
  cout << endl;
  exit(0);
}
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
  cout << " " << to_string(H);
  debug_out(T...);
}
template <typename Head, typename... Tail> void show(Head H, Tail... T) {
  cout << H << " ";
  show(T...);
}
template <typename Head, typename... Tail> void pret(Head H, Tail... T) {
  cout << H << " ";
  pret(T...);
}
#define pr(...) cout << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
typedef long long ll;
#define int ll
typedef long double ld;
typedef vector<int> vi;
#define disp(x) cout << x << " ";
#define rep(i, a, b) for (int i = a; i < (int)b; i++)
#define fo(i, a, b) for (int i = a; i <= (int)b; i++)
#define rf(i, a, b) for (int i = a; i >= (int)b; i--)
#define mp make_pair
#define pb emplace_back
#define F first
#define S second
#define endl '\\n'
// cout.setf(ios::fixed);cout.precision(18)
const int MOD = 998244353;
const int maxn = 3e5 + 10;

int dp[maxn];

void add(int l, int r, int x) {
  if (l >= maxn)
    return;
  dp[l] += x;
  dp[l] %= MOD;
  if (r >= maxn)
    return;
  dp[r + 1] -= x;
  dp[r + 1] %= MOD;
}

int32_t main() {
  fast_io;
  int n, k;
  cin >> n >> k;
  vector<pair<int, int>> v;
  for (int i = 0; i < k; ++i) {
    int l, r;
    cin >> l >> r;
    v.emplace_back(l, r);
  }
  add(1, 1, 1);
  fo(i, 1, n) {
    dp[i] += dp[i - 1];
    dp[i] %= MOD;
    // show(i, dp[i]);
    for (const auto &it : v) {
      add(i + it.first, i + it.second, dp[i]);
    }
  }
  if (dp[n] < 0)
    dp[n] += MOD;
  show(dp[n]);
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sz size()
#define ll long long
#define all(_v) _v.begin(), _v.end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pvllvll pair<vector<ll>, vector<ll>>
#define ld long double
#define veci vector<int>
#define vecll vector<ll>

const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
const double PI = 3.1415926535897932384626433832795;
const double eps = 1e-9;
const int MOD1 = 1e9 + 7;
const int MOD2 = 998244353;

const int MAXN = 2e5 + 10;
int n, k;
veci s;
int dp[MAXN];
bool was[MAXN];
int dfs(int v = 1) {
  if (~dp[v])
    return dp[v];
  int res = (v == n);
  for (auto to : s)
    if (v + to <= n) {
      res += dfs(v + to);
      if (res >= MOD2)
        res -= MOD2;
    }
  return dp[v] = res;
}

void solve() {
  memset(dp, -1, sizeof(dp));
  cin >> n >> k;
  for (int i = 1; i <= k; ++i) {
    int l, r;
    cin >> l >> r;
    while (l <= r)
      was[l++] = 1;
  }
  for (int i = 1; i <= n; ++i)
    if (was[i])
      s.pb(i);
  cout << dfs();
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int T = 1;
  /// cin >> T;
  while (T--)
    solve(), cout << '\\n';
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sz size()
#define ll long long
#define all(_v) _v.begin(), _v.end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pvllvll pair<vector<ll>, vector<ll>>
#define ld long double
#define veci vector<int>
#define vecll vector<ll>

const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
const double PI = 3.1415926535897932384626433832795;
const double eps = 1e-9;
const int MOD1 = 1e9 + 7;
const int MOD2 = 998244353;

const int MAXN = 2e5 + 10;
int n, k;
veci s;
int dp[MAXN];
int p[MAXN];
bool was[MAXN];
pii ed[15];

void solve() {
  cin >> n >> k;
  for (int i = 1; i <= k; ++i)
    cin >> ed[i].f >> ed[i].s;
  dp[1] = p[1] = 1;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= k; ++j) {
      int r = max(0, i - ed[j].f), l = max(0, i - ed[j].s);
      dp[i] = (dp[i] + (p[r] - p[max(l - 1, 0)] + MOD2) % MOD2) % MOD2;
    }
    p[i] = (p[i - 1] + dp[i]) % MOD2;
  }
  cout << dp[n];
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int T = 1;
  /// cin >> T;
  while (T--)
    solve(), cout << '\\n';
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f first
#define s second
#define M 998244353
#define N 200001
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0)

int t, n, k, a, b;
vector<int> off;
ll dp[N];
void printArray(int *, int);

ll solve(int idx) {
  if (idx == n - 1)
    return 1;

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

  ll ans = 0;
  for (int i = 0; i < off.size(); i++) {
    if (idx + off[i] < n)
      ans = (ans + solve(idx + off[i])) % M;
    else
      break;
  }

  return dp[idx] = ans;
}

int main() {
  scanf("%d %d", &n, &k);
  for (int i = 0; i < k; i++) {
    scanf("%d %d", &a, &b);
    for (int j = a; j <= b; j++)
      off.push_back(j);
  }

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

  for (int i = 0; i < n; i++)
    dp[i] = -1;
  printf("%lld\\n", solve(0));
  return 0;
}

void printArray(int *nums, int n) {
  for (int i = 0; i < n; i++)
    printf("%d ", nums[i]);
  printf("\\n");
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f first
#define s second
#define M 998244353
#define N 200001
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0)

int t, n, k, a, b;
vector<pair<int, int>> off;
ll dp[N], suffDP[N + 1];
void printArray(int *, int);

ll sum(int idx, int l, int r) {
  if (r == n - 1)
    return suffDP[idx + l];

  return (suffDP[idx + l] - suffDP[idx + r + 1] + M) % M;
}

ll solve(int idx) {
  if (idx == n - 1)
    return 1;

  ll ans = 0;
  int f = 0;
  for (int i = 0; i < k && !f; i++) {
    if (off[i].s + idx < n)
      ans = (ans + sum(idx, off[i].f, off[i].s)) % M;
    else if (off[i].f + idx >= n)
      f = 1;
    else {
      ans = (ans + sum(idx, off[i].f, n - 1)) % M;
      f = 1;
    }
  }

  return ans;
}

int main() {
  scanf("%d %d", &n, &k);
  for (int i = 0; i < k; i++) {
    scanf("%d %d", &a, &b);
    off.push_back({a, b});
  }

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

  suffDP[n] = 0;
  for (int i = n - 1; i >= 0; i--) {
    dp[i] = solve(i);
    suffDP[i] = (dp[i] + suffDP[i + 1]) % M;
  }

  printf("%lld\\n", dp[0]);
  return 0;
}

void printArray(int *nums, int n) {
  for (int i = 0; i < n; i++)
    printf("%d ", nums[i]);
  printf("\\n");
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sz(x) ((int)x.size())
const ll maxint = 2e18;
const ll minint = -2e18;
/*******\\
(͡ ° ͜ʖ ͡ °) : Hello there, relax.
\\*     */
const int mod = 998244353;
int n;
const int M = 2e5 + 5;
ll done[M];
vector<pair<int, int>> edges;
ll solve(int position) {
  if (position > n)
    return 0;
  if (position == n)
    return 1;
  if (done[position] != -1)
    return done[position];
  ll res = 0;
  for (auto i : edges) {
    if (i.first + position > n)
      break;
    for (int start = i.f; start <= i.s; start++) {
      if (start + position > n)
        break;
      res += solve(position + start) % mod;
      res %= mod;
    }
    if (i.second + position > n)
      break;
  }

  return done[position] = res % mod;
}

int main() {
  memset(done, -1, sizeof(done));
  int k;
  scanf("%d%d", &n, &k);
  edges.assign(k, pair<int, int>());
  for (int i = 0; i < k; i++) {
    scanf("%d%d", &edges[i].f, &edges[i].s);
  }
  sort(edges.begin(), edges.end());
  cout << solve(1) % mod << '\\n';
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sz(x) ((int)x.size())
const ll maxint = 2e18;
const ll minint = -2e18;
/*******\\
(͡ ° ͜ʖ ͡ °) : Hello there, relax.
\\*     */
const int mod = 998244353;
int n;
const int M = 2e5 + 5;
vector<pair<int, int>> edges;
int main() {
  int k;
  scanf("%d%d", &n, &k);
  edges.assign(k, pair<int, int>());
  for (int i = 0; i < k; i++) {
    scanf("%d%d", &edges[i].f, &edges[i].s);
  }
  sort(edges.begin(), edges.end());
  vector<ll> dp(n + 1, 0), sum(n + 1, 0);
  dp[1] = 1;
  sum[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (auto e : edges) {
      dp[i] += ((sum[max(0, i - e.f)] % mod) -
                (sum[max(0, i - e.s - 1)] % mod) + mod) %
               mod;
      dp[i] %= mod;
    }
    sum[i] = (sum[i - 1] % mod + dp[i] % mod) % mod;
    sum[i] %= mod;
  }

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


#include <bits/stdc++.h>

using namespace std;

const int mod = 998244353;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> dp(n + 1);
  dp[0] = 0;
  dp[1] = 1;

  set<int> steps;
  for (int i = 0; i < m; i++) {
    int l, m;
    cin >> l >> m;
    for (int j = l; j <= m; j++) {
      steps.insert(j);
    }
  }

  for (int i = 2; i <= n; i++) {
    dp[i] = 0;
    for (auto it : steps) {
      if ((i - it) > 0 && dp[i - it] > 0) {
        dp[i] = (dp[i] + dp[i - it]) % mod;
      }
    }
  }

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

#include <bits/stdc++.h>

using namespace std;

const long long mod = 998244353;

signed main() {
  long long n, m;
  cin >> n >> m;
  vector<long long> dp(n + 1);
  vector<long long> prefix(n + 1);
  prefix[0] = 0;
  prefix[1] = 1;
  dp[0] = 0;
  dp[1] = 1;

  vector<pair<long long, long long>> steps;
  for (int i = 0; i < m; i++) {
    long long l, m;
    cin >> l >> m;
    steps.push_back({l, m});
  }

  for (int i = 2; i <= n; i++) {
    dp[i] = 0;
    for (auto it : steps) {
      if ((i - it.first) <= 0)
        continue;
      else if ((i - it.second) > 0) {
        int first = max(i - it.first, i - it.second - 1);
        int second = min(i - it.first, i - it.second - 1);
        dp[i] = (dp[i] + prefix[first] - prefix[second]) % mod;
        if (dp[i] < 0) {
          dp[i] += mod;
        }
      } else if ((i - it.first) > 0 && (i - it.second) <= 0) {
        dp[i] = (dp[i] + prefix[i - it.first]) % mod;
      }
    }
    prefix[i] = (prefix[i - 1] + dp[i]) % mod;
    // cout << dp[i] << " " << prefix[i] << endl;
  }

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


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

#define pii pair<int, int>
#define vi vector<int>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define sz(x) (x).size()
#define all(x) (x).begin(), (x).end()  // Forward traversal
#define rall(x) (x).rbegin, (x).rend() // reverse traversal

#define endl "\\n"
#define ll long long
#define ld long double

const ld EPS = 10e-9;
const int INF = 1e9 + 5;
const long long INFLL = (ll)INF * (ll)INF;
const ll MOD = 1e9 + 7;
const ld PI = 3.14159265358979323846;

struct HASH {
  size_t operator()(const pair<int, int> &x) const {
    return hash<long long>()(((long long)x.first) ^
                             (((long long)x.second) << 32));
  }
};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "[";
  for (int i = 0; i < (int)v.size(); ++i) {
    os << v[i];
    if (i != (int)v.size() - 1)
      os << ", ";
  }
  os << "]\\n";
  return os;
}

template <typename T> ostream &operator<<(ostream &os, const set<T> &v) {
  os << "{";
  for (const auto &it : v) {
    os << it;
    if (it != *v.rbegin())
      os << ", ";
  }
  os << "}\\n";
  return os;
}

template <typename T>
ostream &operator<<(ostream &os, const unordered_set<T> &v) {
  os << "{";
  for (const auto &it : v) {
    os << it;
    if (it != *v.rbegin())
      os << ", ";
  }
  os << "}\\n";
  return os;
}

template <typename T, typename S>
ostream &operator<<(ostream &os, const map<T, S> &v) {
  os << "{";
  for (const auto &it : v) {
    os << it.first << " : " << it.second;

    if (it != *v.rbegin())
      os << ", ";
  }

  os << "}\\n";
  return os;
}

template <typename T, typename S>
ostream &operator<<(ostream &os, const unordered_map<T, S> &v) {
  os << "{";
  for (const auto &it : v) {
    os << it.first << " : " << it.second;

    if (it != *v.rbegin())
      os << ", ";
  }

  os << "}\\n";
  return os;
}

template <typename T, typename S>
ostream &operator<<(ostream &os, const pair<T, S> &v) {
  os << "(";
  os << v.first << ", " << v.second << ")";
  os << "\\n";
  return os;
}

#define DEBUG

#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
  cerr << name << " : " << arg1;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
  const char *comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
#else
#define debug(...)
#endif

// __gcd(x, y)

// idea behind binary search: there is monotonically increasing predicate and
// range [l, r]. Find x in range such that x is smallest value for which
// predicate holds true.
//            int lo = 1, hi = 1e9;
//            while(lo < hi)
//            {
//                ll mid = (lo+hi) / 2;
//                if(predicate(mid))
//                {
//                    hi = mid;
//                }
//                else
//                {
//                    lo = mid+1;
//                }
//            }
//            assert(lo == hi);

// OR: given monotonically decreasing predicate, find x in range such that x is
// largest value for which predicate holds true.

// int x = 0;
// for(int s = max_step; s >= 1; s /= 2)
//{
//     while(predicate(x+s)) x += s;
// }
//  after this, x is the largest value for which predicate is true

// How to calculate mid element:
// floor((l+r) / 2) might overflow, use l + floor((r-l)/2)

// ll l = 0, r = s.size()-1;
// ll ans = -1;
// while(l < r)
//{
//     ll mid = l + (r-l) / 2;
//     if(P(mid)) {
//         r = mid;
//         ans = mid;
//     }
//     else
//     {
//         l = mid + 1;
//     }
// }
//
//  AND
//
// ll l = 0, r = s.size()-1;
// ll ans = -1;
// while(l <= r)
//{
//     ll mid = l + (r-l) / 2;
//     if(P(mid)) {
//         r = mid-1;
//         ans = mid;
//     }
//     else
//     {
//         l = mid + 1;
//     }
// }
//
//  ARE EQUIVALENT

#define ull unsigned long long

void solve() {
  int n, k;
  cin >> n >> k;

  vector<pii> segments(k);
  unordered_set<int> moves;
  for (int i = 0; i < k; i++) {
    cin >> segments[i].fi >> segments[i].se;
    for (int l = segments[i].fi; l <= segments[i].se; l++) {
      moves.insert(l);
    }
  }

  const ll mod = 998244353;
  vector<ll> dp(n + 1, 0);
  // dp[i] = num of ways to get to point i
  dp[0] = 1;
  for (int i = 1; i <= n; i++) {
    for (int m : moves) {
      if (i - m >= 0) {
        dp[i] += dp[i - m];
        dp[i] %= mod;
      }
    }
  }

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  solve();

  return 0;
}

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

#define pii pair<int, int>
#define vi vector<int>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define sz(x) (x).size()
#define all(x) (x).begin(), (x).end()  // Forward traversal
#define rall(x) (x).rbegin, (x).rend() // reverse traversal

#define endl "\\n"
#define ll long long
#define ld long double

const ld EPS = 10e-9;
const int INF = 1e9 + 5;
const long long INFLL = (ll)INF * (ll)INF;
const ll MOD = 1e9 + 7;
const ld PI = 3.14159265358979323846;

struct HASH {
  size_t operator()(const pair<int, int> &x) const {
    return hash<long long>()(((long long)x.first) ^
                             (((long long)x.second) << 32));
  }
};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "[";
  for (int i = 0; i < (int)v.size(); ++i) {
    os << v[i];
    if (i != (int)v.size() - 1)
      os << ", ";
  }
  os << "]\\n";
  return os;
}

template <typename T> ostream &operator<<(ostream &os, const set<T> &v) {
  os << "{";
  for (const auto &it : v) {
    os << it;
    if (it != *v.rbegin())
      os << ", ";
  }
  os << "}\\n";
  return os;
}

template <typename T>
ostream &operator<<(ostream &os, const unordered_set<T> &v) {
  os << "{";
  for (const auto &it : v) {
    os << it;
    if (it != *v.rbegin())
      os << ", ";
  }
  os << "}\\n";
  return os;
}

template <typename T, typename S>
ostream &operator<<(ostream &os, const map<T, S> &v) {
  os << "{";
  for (const auto &it : v) {
    os << it.first << " : " << it.second;

    if (it != *v.rbegin())
      os << ", ";
  }

  os << "}\\n";
  return os;
}

template <typename T, typename S>
ostream &operator<<(ostream &os, const unordered_map<T, S> &v) {
  os << "{";
  for (const auto &it : v) {
    os << it.first << " : " << it.second;

    if (it != *v.rbegin())
      os << ", ";
  }

  os << "}\\n";
  return os;
}

template <typename T, typename S>
ostream &operator<<(ostream &os, const pair<T, S> &v) {
  os << "(";
  os << v.first << ", " << v.second << ")";
  os << "\\n";
  return os;
}

#define DEBUG

#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
  cerr << name << " : " << arg1;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
  const char *comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
#else
#define debug(...)
#endif

// __gcd(x, y)

// idea behind binary search: there is monotonically increasing predicate and
// range [l, r]. Find x in range such that x is smallest value for which
// predicate holds true.
//            int lo = 1, hi = 1e9;
//            while(lo < hi)
//            {
//                ll mid = (lo+hi) / 2;
//                if(predicate(mid))
//                {
//                    hi = mid;
//                }
//                else
//                {
//                    lo = mid+1;
//                }
//            }
//            assert(lo == hi);

// OR: given monotonically decreasing predicate, find x in range such that x is
// largest value for which predicate holds true.

// int x = 0;
// for(int s = max_step; s >= 1; s /= 2)
//{
//     while(predicate(x+s)) x += s;
// }
//  after this, x is the largest value for which predicate is true

// How to calculate mid element:
// floor((l+r) / 2) might overflow, use l + floor((r-l)/2)

// ll l = 0, r = s.size()-1;
// ll ans = -1;
// while(l < r)
//{
//     ll mid = l + (r-l) / 2;
//     if(P(mid)) {
//         r = mid;
//         ans = mid;
//     }
//     else
//     {
//         l = mid + 1;
//     }
// }
//
//  AND
//
// ll l = 0, r = s.size()-1;
// ll ans = -1;
// while(l <= r)
//{
//     ll mid = l + (r-l) / 2;
//     if(P(mid)) {
//         r = mid-1;
//         ans = mid;
//     }
//     else
//     {
//         l = mid + 1;
//     }
// }
//
//  ARE EQUIVALENT

#define ull unsigned long long

void solve() {
  int n, k;
  cin >> n >> k;

  vector<pii> segments(k);
  unordered_set<int> moves;
  for (int i = 0; i < k; i++) {
    cin >> segments[i].fi >> segments[i].se;
    for (int l = segments[i].fi; l <= segments[i].se; l++) {
      moves.insert(l);
    }
  }

  const ll mod = 998244353;
  vector<ll> dp(n, 0);
  // dp[i] = num of ways to get to point i
  dp[0] = 1;
  vector<ll> pref = {0};
  pref.pb(dp[0]);
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < k; j++) {
      if (i - segments[j].fi >= 0) {
        int l = i - segments[j].fi + 1;
        int r = max(0, i - segments[j].se);
        dp[i] += pref[l] - pref[r];
        dp[i] %= mod;
      }
    }
    pref.push_back(pref.back() + dp[i]);
  }

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  solve();

  return 0;
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(x) x.begin(), x.end()
typedef long long ll;
ll mod = 998244353;
ll inf = 1e18;
int main() {

  int n, k;
  cin >> n >> k;
  vector<int> l(k), r(k);
  vector<ll> f(n + 5), a(n + 5);
  vector<bool> num(n + 5);
  rep(i, k) {
    cin >> l[i] >> r[i];
    for (int j = l[i]; j <= r[i]; j++)
      num[j] = true;
  }

  a[0] = 0;
  f[0] = 0;
  rep2(i, 1, n) {
    if (num[i]) {
      a[i]++;
      a[i + 1]--;
    }
    f[i] = f[i - 1] + a[i];
    f[i] %= mod;
    rep(j, k) {
      a[i + l[j]] += f[i];
      a[i + l[j]] %= mod;
      a[i + r[j] + 1] -= f[i];
      a[i + r[j] + 1] = (a[i + r[j] + 1] + mod) % mod;
    }
  }
  // rep2(i,1,n) cout << i << ' ' << a[i] << ' ' << f[i] << endl;
  cout << f[n - 1] << endl;

  return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(x) x.begin(), x.end()
typedef long long ll;
ll mod = 998244353;
ll inf = 1e18;
int main() {

  int n, k;
  cin >> n >> k;
  vector<int> l(k), r(k);
  vector<ll> f(2 * n + 5), a(2 * n + 5);
  vector<bool> num(2 * n + 5);
  rep(i, k) {
    cin >> l[i] >> r[i];
    for (int j = l[i]; j <= r[i]; j++)
      num[j] = true;
  }

  a[0] = 0;
  f[0] = 0;
  rep2(i, 1, n) {
    if (num[i]) {
      a[i]++;
      a[i + 1]--;
    }
    f[i] = f[i - 1] + a[i];
    f[i] %= mod;
    rep(j, k) {
      a[i + l[j]] += f[i];
      a[i + l[j]] %= mod;
      a[i + r[j] + 1] -= f[i];
      a[i + r[j] + 1] = (a[i + r[j] + 1] + mod) % mod;
    }
  }
  // rep2(i,1,n) cout << i << ' ' << a[i] << ' ' << f[i] << endl;
  cout << f[n - 1] << endl;

  return 0;
}


#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>

using namespace std;

#define ll long long

const int mod = 998244353;
int n, m;
int l, r;
int a[1000001];
bool vis[1000001];
int dp[1000001];

int main() {
  int num = 0;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d %d", &l, &r);
    for (int j = l; j <= r; j++) {
      if (vis[j])
        continue;
      vis[j] = true;
      a[num++] = j;
    }
  }
  sort(a, a + num);
  dp[0] = 1;
  for (int i = 0; i <= n - 1; i++) {
    for (int j = 0; j < num; j++) {
      if (i + a[j] > n - 1)
        break;
      dp[i + a[j]] = (dp[i] + dp[i + a[j]]) % mod;
    }
  }
  printf("%d\\n", dp[n - 1]);
  return 0;
}

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define ll long long

const int mod = 998244353;
int n, m;
int l, r;
ll dp[200005];
ll sum[200005];
vector<pair<int, int>> vec;

int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d %d", &l, &r);
    vec.push_back(make_pair(l, r));
  }
  dp[0] = sum[0] = 0;
  dp[1] = sum[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < vec.size(); j++) {
      r = max(0, i - vec[j].first);
      l = max(0, i - vec[j].second - 1);
      dp[i] = (dp[i] + (sum[r] - sum[l] + mod)) % mod;
    }
    sum[i] = (sum[i - 1] + dp[i]) % mod;
  }
  printf("%lld\\n", dp[n]);
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define dup(x, y) (((x) + (y)-1) / (y))
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const double EPS = 1e-10;
const int INF = 1e9;
const ll LINF = 1e18;
const double PI = acos(-1);
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

const int MOD = 998244353;

ll dp[200005];

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> l(k), r(k);
  rep(i, k) cin >> l[i] >> r[i];
  dp[0] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < k; j++) {
      for (int d = l[j]; d <= r[j]; d++) {
        if (i - d >= 0) {
          dp[i] += dp[i - d];
          dp[i] %= MOD;
        }
      }
    }
  }
  cout << dp[n - 1] << endl;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define dup(x, y) (((x) + (y)-1) / (y))
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const double EPS = 1e-10;
const int INF = 1e9;
const ll LINF = 1e18;
const double PI = acos(-1);
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

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

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

mint dp[200005];

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> l(k), r(k);
  rep(i, k) cin >> l[i] >> r[i];
  vector<mint> v(n + 1, 0);
  v[1] = 1;
  dp[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < k; j++) {
      int x = max(i - l[j], 0);
      int y = max(i - r[j] - 1, 0);
      mint z = v[x] - v[y];
      dp[i] += z;
    }
    v[i] = v[i - 1] + dp[i];
  }
  cout << dp[n] << endl;
}


#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#define endl '\\n'
using namespace std;
struct _IO {
  _IO() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
  }
} _io;
typedef long long ll;
typedef long double db;

ll exgcd(ll a, ll b, ll &x, ll &y) {
  if (!b) {
    x = 1;
    y = 0;
    return a;
  }
  ll d = exgcd(b, a % b, x, y);
  ll t = x;
  x = y;
  y = t - (a / b) * y;
  return d;
}
ll getInv(ll a, ll mod) {
  ll x, y;
  return exgcd(a, mod, x, y) == 1 ? (x % mod + mod) % mod : -1;
}

const ll maxn = 2e5 + 5, mod = 998244353;
ll dp[maxn], sum[maxn];
bool used[maxn];

int main() {
  ll n, k;
  vector<ll> s;
  vector<pair<ll, ll>> seg;
  cin >> n >> k;
  while (k--) {
    ll a, b;
    cin >> a >> b;
    seg.push_back({a, b});
  }
  sort(seg.begin(), seg.end());
  dp[1] = 1;
  sum[1] = 1;
  for (ll i = 1; i <= n; ++i) {
    for (pair<ll, ll> &j : seg) {
      if (i - j.second - 1 >= 0)
        dp[i] = (dp[i] + sum[i - j.first] - sum[i - j.second - 1]) % mod;
      else
        dp[i] = (dp[i] + sum[i - j.first] - sum[0]) % mod;
    }
    sum[i] = sum[i - 1] + dp[i];
  }
  cout << dp[n] % mod << endl;
  return 0;
}

#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#define endl '\\n'
using namespace std;
struct _IO {
  _IO() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
  }
} _io;
typedef long long ll;
typedef long double db;

ll exgcd(ll a, ll b, ll &x, ll &y) {
  if (!b) {
    x = 1;
    y = 0;
    return a;
  }
  ll d = exgcd(b, a % b, x, y);
  ll t = x;
  x = y;
  y = t - (a / b) * y;
  return d;
}
ll getInv(ll a, ll mod) {
  ll x, y;
  return exgcd(a, mod, x, y) == 1 ? (x % mod + mod) % mod : -1;
}

const ll maxn = 2e5 + 5, mod = 998244353;
ll dp[maxn], sum[maxn];
bool used[maxn];

int main() {
  ll n, k;
  vector<ll> s;
  vector<pair<ll, ll>> seg;
  cin >> n >> k;
  while (k--) {
    ll a, b;
    cin >> a >> b;
    seg.push_back({a, b});
  }
  sort(seg.begin(), seg.end());
  dp[1] = 1;
  sum[1] = 1;
  for (ll i = 1; i <= n; ++i) {
    for (pair<ll, ll> &j : seg) {
      if (i - j.second - 1 >= 0)
        dp[i] = (dp[i] + sum[i - j.first] - sum[i - j.second - 1]) % mod;
      else if (i - j.first >= 0)
        dp[i] = (dp[i] + sum[i - j.first] - sum[0]) % mod;
    }
    sum[i] = sum[i - 1] + dp[i];
  }
  cout << dp[n] % mod << endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\\n'
const int inf = 1000000007;
const ll INF = 1e18;
int mod = 998244353;
// int mod = 1000000007;
const double eps = 1e-8;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template <typename T, typename U> T pow_(T a, U b) {
  return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1;
}
ll modpow(ll a, ll b, ll _mod) {
  return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1;
}
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.F << " " << p.S;
  return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &vec) {
  rep(i, sz(vec)) {
    if (i)
      os << " ";
    os << vec[i];
  }
  return os;
}
template <class T> ostream &operator<<(ostream &os, const set<T> &s) {
  for (auto si : s)
    os << si << " ";
  return os;
}
template <typename T> inline istream &operator>>(istream &is, vector<T> &v) {
  rep(j, sz(v)) is >> v[j];
  return is;
}
template <class T, class T2> inline void add(T &a, T2 b) {
  (a += (b % mod + mod)) %= mod;
}
template <class T> void operator+=(vector<T> &v, vector<T> v2) {
  rep(i, sz(v2)) v.eb(v2[i]);
}

void solve();

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(12);
  int T;
  T = 1;
  while (T--)
    solve();
}

struct mint {
  ll x;
  mint(ll x = 0) : x((mod + x % mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a) { // コンストラクタの、modで割った余りがくる
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a) {
    if ((x += -a.x + mod) >= 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 { // mint(a).pow(t) tは余りとったりしたらあかん
    if (t == 0)
      return 1;
    mint a = pow(t >> 1); // 再帰
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }
  // 逆元
  mint inv() const { return pow(mod - 2); }
  mint &operator/=(const mint a) { // invを利用
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
  friend ostream &operator<<(ostream &s, mint a) { return s << a.x; }
};

void solve() {
  int n, k;
  cin >> n >> k;
  vector<pii> v(k);
  rep(i, k) cin >> v[i].F >> v[i].S;

  vector<mint> acc(n), dp(n);
  dp[0] = 1;

  rep(i, n) {
    if (i) {
      acc[i] += acc[i - 1];
      dp[i] = acc[i];
    }

    rep(j, k) {
      if (i + v[j].F >= n)
        continue;
      acc[i + v[j].F] += dp[i];
      acc[min(n - 1, i + v[j].S) + 1] -= dp[i];
    }
    // cerr << dp[i] << "  " << acc << endl;
  }
  cout << dp[n - 1] << endl;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\\n'
const int inf = 1000000007;
const ll INF = 1e18;
int mod = 998244353;
// int mod = 1000000007;
const double eps = 1e-8;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template <typename T, typename U> T pow_(T a, U b) {
  return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1;
}
ll modpow(ll a, ll b, ll _mod) {
  return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1;
}
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.F << " " << p.S;
  return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &vec) {
  rep(i, sz(vec)) {
    if (i)
      os << " ";
    os << vec[i];
  }
  return os;
}
template <class T> ostream &operator<<(ostream &os, const set<T> &s) {
  for (auto si : s)
    os << si << " ";
  return os;
}
template <typename T> inline istream &operator>>(istream &is, vector<T> &v) {
  rep(j, sz(v)) is >> v[j];
  return is;
}
template <class T, class T2> inline void add(T &a, T2 b) {
  (a += (b % mod + mod)) %= mod;
}
template <class T> void operator+=(vector<T> &v, vector<T> v2) {
  rep(i, sz(v2)) v.eb(v2[i]);
}

void solve();

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(12);
  int T;
  T = 1;
  while (T--)
    solve();
}

struct mint {
  ll x;
  mint(ll x = 0) : x((mod + x % mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a) { // コンストラクタの、modで割った余りがくる
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a) {
    if ((x += -a.x + mod) >= 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 { // mint(a).pow(t) tは余りとったりしたらあかん
    if (t == 0)
      return 1;
    mint a = pow(t >> 1); // 再帰
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }
  // 逆元
  mint inv() const { return pow(mod - 2); }
  mint &operator/=(const mint a) { // invを利用
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
  friend ostream &operator<<(ostream &s, mint a) { return s << a.x; }
};

void solve() {
  int n, k;
  cin >> n >> k;
  vector<pii> v(k);
  rep(i, k) cin >> v[i].F >> v[i].S;

  vector<mint> acc(n + 1), dp(n + 1);
  dp[0] = 1;

  rep(i, n) {
    if (i) {
      acc[i] += acc[i - 1];
      dp[i] = acc[i];
    }

    rep(j, k) {
      if (i + v[j].F >= n)
        continue;
      acc[i + v[j].F] += dp[i];
      acc[min(n - 1, i + v[j].S) + 1] -= dp[i];
    }
    // cerr << dp[i] << "  " << acc << endl;
  }
  cout << dp[n - 1] << endl;
}


#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

// const int MOD = 1e9 + 7;
const int MOD = 998244353;

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

  vector<int> s;

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

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

  int N = s.size();
  sort(s.begin(), s.end());

  vector<ll> dp(n, 0);
  dp[0] = 1;

  for (int i = 1; i < n; i++) {
    for (auto x : s) {
      if (i - x < 0)
        break;
      dp[i] = (dp[i] + dp[i - x]) % MOD;
    }
  }
  cout << dp[n - 1] << endl;

  return 0;
}

#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

// const int MOD = 1e9 + 7;
const int MOD = 998244353;

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

  vector<int> l(k), r(k);

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

  vector<ll> dp(n, 0);
  vector<ll> cum(n, 0); // 累積和
  dp[0] = 1;
  cum[0] = 1;

  for (int i = 1; i < n; i++) {
    for (int j = 0; j < k; j++) {
      int R = i - l[j];
      int L = i - r[j];
      if (R >= 0)
        dp[i] = (dp[i] + cum[R]) % MOD;
      if (L >= 1)
        dp[i] = (dp[i] - cum[L - 1] + MOD) % MOD;
    }
    cum[i] = (dp[i] + cum[i - 1]) % MOD;
  }

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

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define COUT(x) cout << (x) << "\\n"
#define REP(i, n) for (int i = 0; i < n; i++)
#define endl "\\n"
using ll = long long;
const int MOD = 998244353;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> l(k), r(k);
  REP(i, k) cin >> l[i] >> r[i];
  vector<ll> dp(n + 1), dpsum(n + 1);

  dp[1] = 1;
  for (int i = 2; i <= n; i++) {
    REP(j, k) {
      for (int k = l[j]; k <= r[j]; k++) {
        if (i - k < 0)
          continue;
        dp[i] += dp[i - k];
        dp[i] %= MOD;
      }
    }
  }
  COUT(dp[n]);

  /*
  // マス1から始まるため dp[1] = 1 にする
  dp[1] = 1;
  dpsum[1] = 1; // dpの累積和

  for (int i = 2; i <= n; i++) {
    REP(j,k) {
      int li = max(i-r[j], 1);
      int ri = i-l[j];
      if (ri < 0) continue;

      dp[i] += dpsum[ri]-dpsum[li-1];
      // MOD
      dp[i] = dp[i] < 0 ? dp[i]+MOD : dp[i]%MOD;
    }
    dpsum[i] = (dpsum[i-1]+dp[i]) % MOD;
  }
  COUT(dp[n]);
  */
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define COUT(x) cout << (x) << "\\n"
#define REP(i, n) for (int i = 0; i < n; i++)
#define endl "\\n"
using ll = long long;
const int MOD = 998244353;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> l(k), r(k);
  REP(i, k) cin >> l[i] >> r[i];
  vector<ll> dp(n + 1), dpsum(n + 1);

  dp[1] = 1;    // マス1から始まるため dp[1] = 1 にする
  dpsum[1] = 1; // dpの累積和

  for (int i = 2; i <= n; i++) {
    REP(j, k) {
      int li = max(i - r[j], 1);
      int ri = i - l[j];
      if (ri < 0)
        continue; // 右端が範囲外

      dp[i] += dpsum[ri] - dpsum[li - 1];
      dp[i] = dp[i] < 0 ? dp[i] + MOD : dp[i] % MOD; // MOD
    }
    dpsum[i] = (dpsum[i - 1] + dp[i]) % MOD;
  }
  COUT(dp[n]);
  return 0;
}


#include <iostream>
#include <set>
#include <vector>
#define mod 998244353
#define int unsigned long long
using namespace std;
signed main() {
  int n, k;
  cin >> n >> k;
  set<int> s;
  for (int i = 0; i < k; ++i) {
    int a, b;
    cin >> a >> b;
    while (a <= b) {
      s.insert(a);
      ++a;
    }
  }
  vector<int> v;
  for (set<int>::iterator it = s.begin(); it != s.end(); ++it)
    v.push_back(*it);
  int f[n + 1];
  f[1] = 1;
  for (int i = 2; i <= n; ++i) {
    f[i] = 0;
    for (int j = 0; j < v.size(); ++j)
      if (v[j] < i)
        f[i] = (f[i] + f[i - v[j]]) % mod;
      else
        break;
  }
  cout << f[n] << endl;
  return 0;
}