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

#define MOD 998244353

int main() {
  int n, k, sz, l, r, ans = 0;
  cin >> n >> k;
  vector<int> coins, dp(n + 5, 0);
  while (k--) {
    cin >> l >> r;
    for (int i = l; i <= r; i++)
      coins.push_back(i);
  }
  dp[0] = 1;
  for (int i = 0; i <= n; i++) {
    // cout << dp[i] << endl;
    for (auto lol : coins) {
      if (i + lol <= n + 1) {
        dp[i + lol] = (dp[i + lol] + dp[i]) % MOD;
        // cout << i+lol << " " << dp[i+lol] << endl;
      }
    }
    // for(auto lol : dp) cout << lol << " ";
    //	cout << endl ;
  }
  cout << dp[n - 1] << endl;
  return 0;
}

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

#define MOD 998244353

int main() {
  int n, k, sz, l, r, ans = 0;
  cin >> n >> k;
  vector<int> dp(n + 10, 0);
  vector<pair<int, int>> vpp;
  while (k--) {
    cin >> l >> r;
    r++;
    vpp.push_back({l, r});
  }
  dp[0] = 1;
  dp[1] = -1;
  for (int i = 0; i < n; i++) {
    if (i > 0)
      dp[i] = (dp[i] + dp[i - 1]) % MOD;
    for (auto lol : vpp) {
      tie(l, r) = lol;
      if (i + l < n)
        dp[i + l] = (dp[i + l] + dp[i]) % MOD;
      if (i + r < n)
        dp[i + r] = (dp[i + r] - dp[i]) % MOD;
    }
  }
  // for(int i=0;i<n;i++) cout << i << " = " << dp[i] << endl;
  cout << (MOD + dp[n - 1]) % MOD << endl;
  return 0;
}


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

int main() {

  ll mod = 998244353;

  ll n, k, a, b, c;
  vector<int> vec(0);

  cin >> n >> k;

  vector<int> ans(n + 1, 0);

  rep(i, k) {
    cin >> a >> b;
    rep(j, b - a + 1) vec.push_back(a + j);
  }
  sort(vec.begin(), vec.end());

  ans[1] = 1;
  rep(i, n + 1) {
    if (i == 0 || i == 1)
      continue;
    for (int x : vec) {
      if (i - x < 0)
        break;

      ans[i] += ans[i - x];
      ans[i] %= mod;
    }
  }

  cout << ans.at(n);
}

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

int main() {

  int mod = 998244353;

  int n, k, a, b, l, r;

  cin >> n >> k;

  vector<ll> sum(n + 1, 0);
  vector<ll> ans(n + 1, 0);
  vector<pair<int, int>> pair;

  rep(i, k) {
    cin >> a >> b;
    pair.push_back(make_pair(a, b));
  }

  // sort(pair.begin(), pair.end());

  sum[0] = 0;
  sum[1] = 1;
  ans[1] = 1;

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

    rep(j, k) {
      l = i - pair.at(j).second;
      r = i - pair.at(j).first;
      if (r < 0)
        continue;
      l = max(l, 1);

      ans[i] += sum[r] - sum[l - 1];
      ans[i] %= mod;
    }
    sum[i] = (ans[i] + sum[i - 1]) % mod;
  }

  // for(int x: sum) cout << x <<" ";

  if (ans[n] < 0)
    ans[n] += mod;
  cout << ans[n] << endl;
}


// AtCoder :: Beginner Contest 179 :: D - Leaping Tak
// https://atcoder.jp/contests/abc179/tasks/abc179_d

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const ll MOD{998244353};

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, K;
  cin >> N >> K;
  vector<pair<ll, ll>> segments;
  segments.reserve(K);
  for (int i{0}; i < K; ++i) {
    int l, r;
    cin >> l >> r;
    segments.emplace_back(l, r);
  }
  sort(segments.begin(), segments.end());
  vector<ll> dp(N + 1, 0);
  dp[1] = 1;
  for (int i{1}; i <= N; ++i) {
    for (auto s : segments) {
      if (s.first > N) {
        break;
      }
      for (ll j{s.first}; j <= s.second; j++) {
        if (i + j <= N) {
          dp[i + j] = dp[i + j] + dp[i] % MOD;
        } else {
          break;
        }
      }
    }
  }
  cout << (dp[N] % MOD) << endl;
  return EXIT_SUCCESS;
}

// AtCoder :: Beginner Contest 179 :: D - Leaping Tak
// https://atcoder.jp/contests/abc179/tasks/abc179_d

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const ll MOD{998244353};
const int MAXN{200000};

vector<pair<int, int>> segments;
vector<ll> dp(MAXN + 1, 0);

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, K;
  cin >> N >> K;
  segments.reserve(K);
  for (int i{0}; i < K; ++i) {
    int l, r;
    cin >> l >> r;
    segments.emplace_back(l, r);
  }

  // Start on [1, 2)
  ll acc{1};
  for (int i{1}; i < N; ++i) {
    acc = (acc + dp[i]) % MOD;
    if (acc > 0) {
      for (auto [sl, sr] : segments) {
        if (i + sl <= N) {
          dp[i + sl] = (dp[i + sl] + acc) % MOD;
        }
        if (i + sr + 1 <= N) {
          dp[i + sr + 1] = (dp[i + sr + 1] - acc) % MOD;
          if (dp[i + sr + 1] < 0) {
            dp[i + sr + 1] += MOD;
          }
        }
      }
    }
  }
  cout << (dp[N] % MOD) << endl;
  return EXIT_SUCCESS;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
const ll MOD = 998244353;
const long double PI = 3.14159265358979;
const ll MAX = 0;

ll DP[200020];

int main() {

  ll N, K;
  cin >> N >> K;
  ll L[K];
  ll R[K];
  rep(i, K) { cin >> L[i] >> R[i]; }
  DP[0] = 1;
  DP[1] = -1;
  rep(i, N) {
    rep(j, K) {
      DP[i + L[j]] += DP[i];
      DP[i + L[j]] %= MOD;
      DP[i + R[j] + 1] -= DP[i];
      DP[i + R[j] + 1] %= MOD;
    }
    DP[i + 1] += DP[i];
    DP[i + 1] %= MOD;
  }
  while (DP[N - 1] < 0) {
    DP[N - 1] += MOD;
  }
  cout << DP[N - 1];
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
const ll MOD = 998244353;
const long double PI = 3.14159265358979;
const ll MAX = 0;

ll DP[600020];

int main() {

  ll N, K;
  cin >> N >> K;
  ll L[K];
  ll R[K];
  rep(i, K) { cin >> L[i] >> R[i]; }
  DP[0] = 1;
  DP[1] = -1;
  rep(i, N) {
    rep(j, K) {
      DP[i + L[j]] += DP[i];
      DP[i + L[j]] %= MOD;
      DP[i + R[j] + 1] -= DP[i];
      DP[i + R[j] + 1] %= MOD;
    }
    DP[i + 1] += DP[i];
    DP[i + 1] %= MOD;
  }
  while (DP[N - 1] < 0) {
    DP[N - 1] += MOD;
  }
  cout << DP[N - 1];
}


#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
long long dp[200001];
long long pre[200001];
int main() {
  long long n, k;
  cin >> n >> k;
  vector<pair<long long, long long>> S;
  for (long long i = 0; i < k; i++) {
    long long l, r;
    cin >> l >> r;
    S.push_back({l, r});
  }
  dp[0] = 0;
  dp[1] = 1;
  dp[2] = -1;
  for (int i = 1; i <= n; i++) {
    dp[i] = (dp[i] % mod + dp[i - 1] % mod) % mod;
    for (int j = 0; j < k; j++) {
      int l = S[j].first;
      int r = S[j].second;
      if (i + l <= n) {
        dp[i + l] += dp[i];
        dp[i + r + 1] %= mod;
      }
      if (i + r + 1 <= n) {
        dp[i + r + 1] = (dp[i + r + 1] - dp[i] + mod) % mod;
        dp[i + r + 1] %= mod;
      }
    }
  }
  cout << dp[n] << endl;
}

#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
long long dp[200001];
long long pre[200001];
int main() {
  long long n, k;
  cin >> n >> k;
  vector<pair<long long, long long>> S;
  for (long long i = 0; i < k; i++) {
    long long l, r;
    cin >> l >> r;
    S.push_back({l, r});
  }
  dp[0] = 0;
  dp[1] = 1;
  dp[2] = -1;
  for (int i = 1; i <= n; i++) {
    dp[i] = (dp[i] % mod + dp[i - 1] % mod) % mod;
    for (int j = 0; j < k; j++) {
      int l = S[j].first;
      int r = S[j].second;
      if (i + l <= n) {
        dp[i + l] += dp[i];
        dp[i + l] %= mod;
      }
      if (i + r + 1 <= n) {
        dp[i + r + 1] = (dp[i + r + 1] - dp[i] + mod) % mod;
        dp[i + r + 1] %= mod;
      }
    }
  }
  cout << dp[n] << endl;
}


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

int main(int argc, char *argv[]) {
  int n, k;
  std::cin >> n >> k;

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

    for (int j = l; j <= r; ++j) {
      s.push_back(j);
    }
  }
  std::sort(s.begin(), s.end());

  int x = 998244353;

  std::vector<long> dp(n + 1);
  dp[1] = 1;
  for (int i = 1; i < n; ++i) {
    for (int d : s) {
      int j = i + d;
      if (j > n) {
        break;
      }
      dp[j] += dp[i];
    }
  }

  std::cout << dp[n] % x << std::endl;

  return 0;
}

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

int main(int argc, char *argv[]) {
  int n, k;
  std::cin >> n >> k;

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

  int mod = 998244353;

  std::vector<long> dp(n + 1, 0);
  std::vector<long> dpsum(n + 1, 0);
  dp[1] = 1;
  dpsum[1] = 1;
  for (int i = 2; i <= n; ++i) {
    for (auto d : s) {
      long l = std::max(i - d.second, 1);
      long r = i - d.first;
      if (r < 1) {
        continue;
      }

      dp[i] += dpsum[r] - dpsum[l - 1];
      dp[i] %= mod;
    }

    dpsum[i] = dpsum[i - 1] + dp[i];
  }

  std::cout << dp[n] << std::endl;

  return 0;
}


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

const ll INF = 1LL << 60;
const ll MOD = 998244353;
ll dp[200020];

int main() {
  int N, K;
  cin >> N >> K;
  int l[10], r[10];
  REP(i, K) cin >> l[i] >> r[i];

  dp[1] = 1;
  dp[2] = -1;
  for (int i = 1; i <= N; i++) {
    dp[i] = (dp[i] + dp[i - 1]) % MOD;
    REP(j, K) {
      if (i + l[j] <= N)
        dp[i + l[j]] = (dp[i + l[j]] + dp[i]) % MOD;
      if (i + r[j] + 1 <= N)
        dp[i + r[j] + 1] = dp[i + r[j] + 1] - dp[i];
      if (dp[i + r[j] + 1] < 0)
        dp[i + r[j] + 1] += MOD;
    }
    //    REP(i,N+1) cout << dp[i] << " ";
    //    cout << endl;
  }
  cout << dp[N] << endl;
}

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

const ll INF = 1LL << 60;
const ll MOD = 998244353;
ll dp[200020];

int main() {
  int N, K;
  cin >> N >> K;
  int l[10], r[10];
  REP(i, K) cin >> l[i] >> r[i];

  dp[1] = 1;
  dp[2] = -1;
  for (int i = 1; i <= N; i++) {
    dp[i] = (dp[i] + dp[i - 1]) % MOD;
    REP(j, K) {
      if (i + l[j] <= N)
        dp[i + l[j]] = (dp[i + l[j]] + dp[i]) % MOD;
      if (i + r[j] + 1 <= N) {
        dp[i + r[j] + 1] = dp[i + r[j] + 1] - dp[i];
        if (dp[i + r[j] + 1] < 0)
          dp[i + r[j] + 1] += MOD;
      }
    }
    //    REP(i,N+1) cout << dp[i] << " ";
    //    cout << endl;
  }
  cout << dp[N] << endl;
}