#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const int mod = 998244353;
int dp[N] = {};
int L[20] = {}, R[20] = {};
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= m; i++)
    cin >> L[i] >> R[i];
  dp[1] = 1;
  for (int i = 2; i <= n; i++)
    for (int j = 1; j <= m; j++)
      for (int k = max(1, i - R[j]); k <= i - L[j]; k++)
        dp[i] = (dp[i] + dp[k]) % mod;
  cout << dp[n] << '\\n';
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const long long mod = 998244353;
long long dp[N] = {};
long long sum[N] = {};
int L[20] = {}, R[20] = {};
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= m; i++)
    cin >> L[i] >> R[i];
  dp[1] = sum[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 1; j <= m; j++)
      dp[i] = (dp[i] + sum[max(0, i - L[j])] - sum[max(0, i - R[j] - 1)]) % mod;
    sum[i] = (sum[i - 1] + dp[i]) % mod;
  }
  dp[n] %= mod;
  if (dp[n] < 0)
    dp[n] += mod;
  cout << dp[n] << '\\n';
  return 0;
}


#include <algorithm>
#include <cassert>
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define pb push_back
#define FOR(i, n) for (int i = 0; i < (n); i++)
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;

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

void fact_init(int n);
ll exp(ll taban, ll us, ll md);
ll ebob(ll a, ll b);
ll ekok(ll a, ll b);
ll komb(ll a, ll b);

vector<ll> fact;
vector<ll> inv_fact;
void fact_init(int n) {
  fact.resize(n + 5);
  inv_fact.resize(n + 5);
  fact[0] = inv_fact[0] = 1;
  for (int i = 1; i <= n; i++) {
    fact[i] = (fact[i - 1] * i) % mod;
    inv_fact[i] = exp(fact[i], mod - 2, mod);
  }
}
ll exp(ll taban, ll us, ll md) {
  ll carpan = taban % md;
  if (carpan == 0)
    return 0;
  ll temp = us;
  ll res = 1;
  while (temp) {
    if (temp % 2)
      res = (res * carpan) % md;
    temp /= 2;
    carpan = (carpan * carpan) % md;
  }
  return res;
}

ll ebob(ll a, ll b) {
  if (!a)
    return b;
  return ebob(b % a, a);
}

ll ekok(ll a, ll b) { return (a * b) / ebob(a, b); }

ll komb(ll a, ll b) {
  if (a < b)
    return 0;
  return fact[a] * (inv_fact[a - b] * inv_fact[b] % mod) % mod;
}
const int N = 1e5 + 5;
int seg[4 * N];
void update(int cur, int l, int r, int tar, int val) {
  int mid = (l + r) / 2;
  if (l > tar)
    return;
  if (l == r) {
    if (l == tar)
      seg[cur] = (seg[cur] + val) % mod;
    return;
  }
  update(2 * cur, l, mid, tar, val);
  update(2 * cur + 1, mid + 1, r, tar, val);
  seg[cur] = (seg[2 * cur] + seg[2 * cur + 1]) % mod;
}
int get(int cur, int l, int r, int tl, int tr) {
  int mid = (l + r) / 2;
  if (tl > r || l > tr)
    return 0;
  if (tl <= l && r <= tr)
    return seg[cur];
  return (get(2 * cur, l, mid, tl, tr) + get(2 * cur + 1, mid + 1, r, tl, tr)) %
         mod;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n, k;
  cin >> n >> k;
  int l[k], r[k];
  for (int i = 0; i < k; i++)
    cin >> l[i] >> r[i];
  update(1, 0, n, 1, 1);
  for (int i = 2; i <= n; i++) {
    int res = 0;
    for (int j = 0; j < k; j++) {
      res = (res + get(1, 0, n, max(0, i - r[j]), max(0, i - l[j]))) % mod;
      // cout<<i<<" "<<get(1, 0, n, max(0, i - r[j]), max(0, i - l[j]))<<"\\n";
    }
    update(1, 0, n, i, res);
    // cout<<get(1, 0, n, 0, 0)<<"\\n";
  }
  cout << get(1, 0, n, n, n) << "\\n";
}

#include <algorithm>
#include <cassert>
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define pb push_back
#define FOR(i, n) for (int i = 0; i < (n); i++)
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;

const int mod = 1e9 + 7;
const int mod2 = 998244353;

void fact_init(int n);
ll exp(ll taban, ll us, ll md);
ll ebob(ll a, ll b);
ll ekok(ll a, ll b);
ll komb(ll a, ll b);

vector<ll> fact;
vector<ll> inv_fact;
void fact_init(int n) {
  fact.resize(n + 5);
  inv_fact.resize(n + 5);
  fact[0] = inv_fact[0] = 1;
  for (int i = 1; i <= n; i++) {
    fact[i] = (fact[i - 1] * i) % mod;
    inv_fact[i] = exp(fact[i], mod - 2, mod);
  }
}
ll exp(ll taban, ll us, ll md) {
  ll carpan = taban % md;
  if (carpan == 0)
    return 0;
  ll temp = us;
  ll res = 1;
  while (temp) {
    if (temp % 2)
      res = (res * carpan) % md;
    temp /= 2;
    carpan = (carpan * carpan) % md;
  }
  return res;
}

ll ebob(ll a, ll b) {
  if (!a)
    return b;
  return ebob(b % a, a);
}

ll ekok(ll a, ll b) { return (a * b) / ebob(a, b); }

ll komb(ll a, ll b) {
  if (a < b)
    return 0;
  return fact[a] * (inv_fact[a - b] * inv_fact[b] % mod) % mod;
}
const int N = 2e5 + 5;
int seg[4 * N];
void update(int cur, int l, int r, int tar, int val) {
  int mid = (l + r) / 2;
  if (!(l <= tar && tar <= r))
    return;
  if (l == r) {
    seg[cur] = (seg[cur] + val) % mod2;
    return;
  }
  update(2 * cur, l, mid, tar, val);
  update(2 * cur + 1, mid + 1, r, tar, val);
  seg[cur] = (seg[2 * cur] + seg[2 * cur + 1]) % mod2;
}
int get(int cur, int l, int r, int tl, int tr) {
  int mid = (l + r) / 2;
  if (tl > r || l > tr)
    return 0;
  if (tl <= l && r <= tr)
    return seg[cur];
  return (get(2 * cur, l, mid, tl, tr) + get(2 * cur + 1, mid + 1, r, tl, tr)) %
         mod2;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n = 5e4, k = 10;
  cin >> n >> k;
  int l[k], r[k];
  for (int i = 0; i < k; i++) {
    l[i] = rand() % n;
    r[i] = min(n, l[i] + rand() % n);
    cin >> l[i] >> r[i];
  }
  update(1, 0, n, 1, 1);
  for (int i = 2; i <= n; i++) {
    int res = 0;
    for (int j = 0; j < k; j++) {
      res = (res + get(1, 0, n, max(0, i - r[j]), max(0, i - l[j]))) % mod2;
    }
    update(1, 0, n, i, res);
  }
  cout << get(1, 0, n, n, n) << "\\n";
}


#include <bits/stdc++.h>
#define INF 1e9
#define MOD 998244353
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main(void) {
  int N, K;
  cin >> N >> K;
  vector<pii> lr(K);
  for (int i = 0; i < K; i++) {
    cin >> lr[i].first >> lr[i].second;
  }

  vector<ll> dp(N + 1, 0);
  dp[0] = 0;
  dp[1] = 1;
  for (int i = 1; i <= N; i++) {
    for (int j = 0; j < K; j++) {
      for (int d = lr[j].first; d <= min(N - i, lr[j].second); d++) {
        dp[i + d] += dp[i];
        dp[i + d] %= MOD;
      }
    }
  }

  cout << dp[N] << endl;

  return 0;
}

#include <bits/stdc++.h>
#define INF 1e9
#define MOD 998244353
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main(void) {
  int N, K;
  cin >> N >> K;
  vector<pii> lr(K);
  for (int i = 0; i < K; i++) {
    cin >> lr[i].first >> lr[i].second;
    lr[i].second++;
  }

  vector<ll> dp(N + 1, 0);
  dp[0] = 1;
  dp[1] = -1;

  for (int i = 0; i < N; i++) {
    if (i > 0) {
      dp[i] += dp[i - 1];
      dp[i] %= MOD;
    }
    for (int j = 0; j < K; j++) {
      if (i + lr[j].first < N) {
        dp[i + lr[j].first] += dp[i];
        dp[i + lr[j].first] %= MOD;
      }
      if (i + lr[j].second < N) {
        dp[i + lr[j].second] += (MOD - dp[i]);
        dp[i + lr[j].second] %= MOD;
      }
    }
  }

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

  return 0;
}


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

template <typename T> void drop(const T &x) {
  cout << x << '\\n';
  exit(0);
}

const long long mod = 998244353;

void milkshake() {
  int n, k;
  cin >> n >> k;
  vector<int> t(n + 1);
  vector<int> s;
  for (int i = 0; i < k; i++) {
    int a, b;
    cin >> a >> b;
    for (int i = a; i <= b; i++) {
      t[i] = 1;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (t[i])
      s.push_back(i);
  }

  vector<long long> dp(n + 1);
  dp[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < (int)s.size(); j++) {
      if (i - s[j] < 1)
        continue;
      dp[i] = (dp[i] + dp[i - s[j]]) % mod;
    }
  }
  cout << dp[n] % mod << '\\n';
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--)
    milkshake();

  return 0;
}

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

template <typename T> void drop(const T &x) {
  cout << x << '\\n';
  exit(0);
}

const long long mod = 998244353;

void milkshake() {
  int n, k;
  cin >> n >> k;
  vector<int> l(k), r(k);
  for (int i = 0; i < k; i++) {
    cin >> l[i] >> r[i];
  }
  vector<long long> dp(n + 1);
  vector<long long> dps(n + 1);
  dp[1] = dps[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < k; j++) {
      int li = i - r[j];
      li = max(li, 1);
      int ri = i - l[j];
      if (ri < 1)
        continue;
      dp[i] = (dp[i] + dps[ri] - dps[li - 1]) % mod;
    }
    dps[i] = (dps[i - 1] + dp[i]) % mod;
  }
  cout << (dp[n] + mod) % mod << '\\n';
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--)
    milkshake();

  return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/tree_policy.hpp>

const double pi = 3.141592653589793238462643383279;
using namespace std;
using namespace __gnu_pbds;
// typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

// container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SQ(a) ((a) * (a))
#define EACH(i, c)                                                             \\
  for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

// repetition
//------------------------------------------
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define MOD 1000000007

#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

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

#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)

const long double EPS = 1e-6, PI = acos((long double)-1);

// ここから編集

const int MOD2 = 998244353;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(7);

  int N, K;
  cin >> N >> K;
  vector<pair<int, int>> p;
  REP(i, K) {
    int l, r;
    cin >> l >> r;
    r++;
    p.push_back({l, r});
  }
  vector<ll> dp(N);
  dp[0] = 1;
  dp[1] = -1;
  for (int i = 0; i < N; i++) {
    if (i > 0)
      dp[i] += dp[i - 1];
    dp[i] %= MOD2;
    for (int j = 0; j < K; j++) {
      int l = p[j].first, r = p[j].second;
      if (i + l < N)
        dp[i + l] += dp[i];
      dp[i + l] %= MOD2;
      if (i + r < N)
        dp[i + r] = (dp[i + r] - dp[i] + MOD2) % MOD2;
      dp[i + r] %= MOD2;
    }
  }
  cout << dp[N - 1] << endl;

  return 0;
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/tree_policy.hpp>

const double pi = 3.141592653589793238462643383279;
using namespace std;
using namespace __gnu_pbds;
// typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

// container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SQ(a) ((a) * (a))
#define EACH(i, c)                                                             \\
  for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

// repetition
//------------------------------------------
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define MOD 1000000007

#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

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

#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)

const long double EPS = 1e-6, PI = acos((long double)-1);

// ここから編集

const int MOD2 = 998244353;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(7);

  int N, K;
  cin >> N >> K;
  vector<pair<int, int>> p;
  REP(i, K) {
    int l, r;
    cin >> l >> r;
    r++;
    p.push_back({l, r});
  }
  vector<ll> dp(N);
  dp[0] = 1;
  dp[1] = -1;
  for (int i = 0; i < N; i++) {
    if (i > 0)
      dp[i] += dp[i - 1];
    dp[i] %= MOD2;
    for (int j = 0; j < K; j++) {
      int l = p[j].first, r = p[j].second;
      if (i + l < N) {
        dp[i + l] += dp[i];
        dp[i + l] %= MOD2;
      }
      if (i + r < N) {
        dp[i + r] = (dp[i + r] - dp[i] + MOD2) % MOD2;
      }
    }
  }
  cout << dp[N - 1] << endl;

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ar array
#define ll long long

const int MAX_N = 1e5 + 1;
const int MOD = 998244353;
const int INF = 1e9;
const ll LINF = 1e18;

void solve() {
  int n, k;
  cin >> n >> k;
  vector<int> dp(n + 1), a;
  for (int i = 0; i < k; i++) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++)
      a.push_back(j);
  }
  sort(a.begin(), a.end());
  dp[1] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < a.size() && i + a[j] <= n; j++) {
      dp[i + a[j]] = (dp[i + a[j]] + dp[i]) % MOD;
    }
  }
  cout << dp[n] << "\\n";
}

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

  int tc;
  tc = 1;
  for (int t = 1; t <= tc; t++) {
    // cout << "Case #" << t  << ": ";
    solve();
  }
}

#include <bits/stdc++.h>

using namespace std;

#define ar array
#define ll long long

const int MAX_N = 1e5 + 1;
const int MOD = 998244353;
const int INF = 1e9;
const ll LINF = 1e18;

void solve() {
  int n, k;
  cin >> n >> k;
  ar<int, 2> arr[n];
  for (int i = 0; i < k; i++)
    cin >> arr[i][0] >> arr[i][1];
  vector<int> dp(n);
  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 (int j = 0; j < k; j++) {
      auto [l, r] = arr[j];
      if (i + l < n)
        dp[i + l] = (dp[i + l] + dp[i]) % MOD;
      if (i + r + 1 < n)
        dp[i + r + 1] = (dp[i + r + 1] - dp[i] + MOD) % MOD;
    }
  }
  cout << dp[n - 1] << "\\n";
}

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

  int tc;
  tc = 1;
  for (int t = 1; t <= tc; t++) {
    // cout << "Case #" << t  << ": ";
    solve();
  }
}


#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvl = vector<vector<long>>;
using pii = pair<int, int>;
using pil = pair<int, long>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, s, t) for (int i = s; i < t; i++)
#define RNG(i, s, t, u) for (int i = s; i < t; i += u)
#define MOD 998244353
#define all(vec) vec.begin(), vec.end()
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  long n, k;
  cin >> n >> k;
  vector<pll> data(k);
  rep(i, k) cin >> data.at(i).first >> data.at(i).second;
  vector<long> dp(200010, 0);
  vector<long> imos(200010, 0);
  dp.at(1) = 1;
  long acm = 0;
  REP(v, 1, n) {
    if (v == 1) {
      rep(i, k) {
        imos.at(v + data.at(i).first) += 1;
        imos.at(v + data.at(i).second + 1) -= 1;
      }
    } else {
      acm += imos.at(v);
      acm %= MOD;
      dp.at(v) = acm;
      rep(i, k) {
        imos.at(v + data.at(i).first) += acm;
        imos.at(v + data.at(i).first) % MOD;
        imos.at(v + data.at(i).second + 1) -= acm;
        imos.at(v + data.at(i).second + 1) += MOD;
        imos.at(v + data.at(i).second + 1) %= MOD;
      }
    }
  }
  // rep(i,n+1) cout << dp.at(i) << " ";
  // cout << endl;
  // cout << imos.at(n) << endl;
  cout << (acm + imos.at(n)) % MOD << endl;
}

#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvl = vector<vector<long>>;
using pii = pair<int, int>;
using pil = pair<int, long>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, s, t) for (int i = s; i < t; i++)
#define RNG(i, s, t, u) for (int i = s; i < t; i += u)
#define MOD 998244353
#define all(vec) vec.begin(), vec.end()
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  long n, k;
  cin >> n >> k;
  vector<pll> data(k);
  rep(i, k) cin >> data.at(i).first >> data.at(i).second;
  vector<long> dp(500010, 0);
  vector<long> imos(500010, 0);
  dp.at(1) = 1;
  long acm = 0;
  REP(v, 1, n) {
    if (v == 1) {
      rep(i, k) {
        imos.at(v + data.at(i).first) += 1;
        imos.at(v + data.at(i).second + 1) -= 1;
      }
    } else {
      acm += imos.at(v);
      acm %= MOD;
      dp.at(v) = acm;
      rep(i, k) {
        imos.at(v + data.at(i).first) += acm;
        imos.at(v + data.at(i).first) % MOD;
        imos.at(v + data.at(i).second + 1) -= acm;
        imos.at(v + data.at(i).second + 1) += MOD;
        imos.at(v + data.at(i).second + 1) %= MOD;
      }
    }
  }
  // rep(i,n+1) cout << dp.at(i) << " ";
  // cout << endl;
  // cout << imos.at(n) << endl;
  cout << (acm + imos.at(n)) % MOD << endl;
}


#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using ll = long long;
using ull = unsigned long long;
using namespace std;

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; (i) < ((int)(n)); ++(i))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define test(a)                                                                \\
  cout << "line:" << __LINE__ << "[" << (#a) << ": " << (a) << "]" << endl

constexpr int INF = 1e9 + 7;
constexpr ll INFL = 9 * 1e18;

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

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

int inline digit(ll num) {
  int tmp = 0;
  while (num) {
    tmp++;
    num /= 10;
  }
  return tmp;
} // 桁数
template <typename T> inline T SUM(vector<T> vec) {
  return accumulate(all(vec), (T)0);
} // vectorの中身を全部足す
template <typename T> inline T digitSum(T num) {
  T sum = 0;
  while (num) {
    sum += num % 10;
    num /= 10;
  }
  return sum;
} // 各桁の和
template <typename T> inline T gcd(T a, T b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
} // 最大公約数
template <typename T> inline T lcm(T a, T b) {
  T g = gcd(a, b);
  return a / g * b;
} // 最小公倍数
template <typename T> inline T power(T a, T b) {
  T tmp = 1;
  rep(i, b) { tmp *= a; }
  return tmp;
} // 累乗
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T> inline void print(T &&x) {
  cout << setprecision(32) << x << endl;
}

// TODO: write
int main() {
  ll waru = 998244353;
  int n, k;
  cin >> n >> k;
  vector<int> s(n + 1, 0);
  vector<ll> dp(n + 1, 0);
  vector<pair<int, int>> lr(k);
  rep(i, k) {
    int l, r;
    cin >> l >> r;
    r++;
    lr[i] = (mp(l, r));
    for (int j = l; j <= r; ++j) {
      s[j] = 1;
    }
  }

  dp[1] = 1;
  vector<int> kA(k, 0);
  for (int i = 2; i <= n; ++i) {
    rep(j, k) {
      if (i - lr[j].se > 0) {
        kA[j] -= dp[i - lr[j].se];
        kA[j] %= waru;
        if (kA[j] < 0)
          kA[j] += waru;
        // test(i);
        // test(lr[j].se);
        // test(kA[j]);
      }
      if (i - lr[j].fi > 0) {
        kA[j] += dp[i - lr[j].fi];
        kA[j] %= waru;
        // test(i-lr[j].fi);
        // test(kA[j]);
      }
      dp[i] += kA[j];
      dp[i] %= waru;
    }
  }

  // for(int i = 2;i <= n;++i){
  //   rep(j,i){
  //     if(s[j+1]){
  //       dp[i] += dp[i-j-1];
  //       dp[i] %= waru;
  //     }
  //   }
  // }

  print(dp[n]);
  return 0;
}

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using ll = long long;
using ull = unsigned long long;
using namespace std;

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; (i) < ((int)(n)); ++(i))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define test(a)                                                                \\
  cout << "line:" << __LINE__ << "[" << (#a) << ": " << (a) << "]" << endl

constexpr int INF = 1e9 + 7;
constexpr ll INFL = 9 * 1e18;

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

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

int inline digit(ll num) {
  int tmp = 0;
  while (num) {
    tmp++;
    num /= 10;
  }
  return tmp;
} // 桁数
template <typename T> inline T SUM(vector<T> vec) {
  return accumulate(all(vec), (T)0);
} // vectorの中身を全部足す
template <typename T> inline T digitSum(T num) {
  T sum = 0;
  while (num) {
    sum += num % 10;
    num /= 10;
  }
  return sum;
} // 各桁の和
template <typename T> inline T gcd(T a, T b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
} // 最大公約数
template <typename T> inline T lcm(T a, T b) {
  T g = gcd(a, b);
  return a / g * b;
} // 最小公倍数
template <typename T> inline T power(T a, T b) {
  T tmp = 1;
  rep(i, b) { tmp *= a; }
  return tmp;
} // 累乗
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T> inline void print(T &&x) {
  cout << setprecision(32) << x << endl;
}

constexpr int SIZE = 200020;
int s[SIZE];
ll dp[SIZE];
int kA[SIZE];
pair<int, int> lr[10];
// TODO: write
int main() {
  ll waru = 998244353;
  int n, k;
  cin >> n >> k;
  rep(i, k) {
    int l, r;
    cin >> l >> r;
    r++;
    lr[i] = (mp(l, r));
    for (int j = l; j <= r; ++j) {
      s[j] = 1;
    }
  }

  dp[1] = 1;
  for (int i = 2; i <= n; ++i) {
    rep(j, k) {
      if (i - lr[j].se > 0) {
        kA[j] -= dp[i - lr[j].se];
        kA[j] %= waru;
        if (kA[j] < 0)
          kA[j] += waru;
        // test(i);
        // test(lr[j].se);
        // test(kA[j]);
      }
      if (i - lr[j].fi > 0) {
        kA[j] += dp[i - lr[j].fi];
        kA[j] %= waru;
        // test(i-lr[j].fi);
        // test(kA[j]);
      }
      dp[i] += kA[j];
      dp[i] %= waru;
    }
  }

  // for(int i = 2;i <= n;++i){
  //   rep(j,i){
  //     if(s[j+1]){
  //       dp[i] += dp[i-j-1];
  //       dp[i] %= waru;
  //     }
  //   }
  // }

  print(dp[n]);
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep1(i, n) for (ll i = 1; i <= n; ++i)
#define revrep(i, n) for (ll i = n - 1; i >= 0; --i)
inline constexpr ll Inf = (1ULL << 62) - 1;
#define fastio                                                                 \\
  cin.tie(nullptr);                                                            \\
  ios_base::sync_with_stdio(false);
#define endl '\\n'
template <class T> bool updmax(T &a, T b) {
  if (b > a) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool updmin(T &a, T b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}
template <class T> T permutation(ll n, ll k) {
  T f(1);
  for (ll i = 0; i < k; ++i, --n)
    f *= n;
  return f;
}
template <class T> T factorial(ll n) { return permutation<T>(n, n); }
template <class T> T binomial(ll n, ll k) {
  return permutation<T>(n, k) /= factorial<T>(k);
}

template <ll Mod> class modint {
public:
  ll n = 0;
  modint() {}
  modint(ll n) : n(n) { clamp(); }
  modint &operator=(modint const &a) = default;
  modint &operator=(int a) {
    n = a;
    clamp();
    return *this;
  }
  modint operator-() {
    modint t = *this;
    t.n = -t.n;
    t.clamp();
    return t;
  }
  modint &operator*=(modint const &a) {
    n *= a.n;
    clamp();
    return *this;
  }
  modint &operator*=(ll a) {
    n *= a;
    clamp();
    return *this;
  }
  modint &operator/=(modint const &a) {
    *this *= a.inv();
    return *this;
  }
  modint &operator+=(modint const &a) {
    n += a.n;
    if (n >= Mod)
      n -= Mod;
    return *this;
  }
  modint &operator-=(modint const &a) {
    n -= a.n;
    if (n < 0)
      n += Mod;
    return *this;
  }
  modint &operator%=(modint const &a) {
    n %= a.n;
    clamp();
    return *this;
  }
  friend modint operator*(modint a, modint b) {
    modint t(a);
    t.n *= b.n;
    t.clamp();
    return t;
  }
  friend modint operator+(modint a, modint b) {
    modint t(a);
    t.n += b.n;
    t.clamp();
    return t;
  }
  friend modint operator-(modint a, modint b) {
    modint t(a);
    t.n -= b.n;
    t.clamp();
    return t;
  }
  friend ostream &operator<<(ostream &os, modint const &a) {
    os << a.n;
    return os;
  }
  friend bool operator==(modint const &a, int b) { return a.n == b; }
  void clamp() {
    n %= Mod;
    if (n < 0)
      n += Mod;
  }
  modint inv() const { return this->pow(Mod - 2); }
  ll get() { return n; }
  modint pow(ll p) const {
    ll a = 1, e = n;
    while (p > 0) {
      if (p & 1) {
        a *= e;
        a %= Mod;
      }
      e *= e;
      e %= Mod;
      p >>= 1;
    }
    return modint(a);
  }
};

const ll Mod = 998244353;
using mint = modint<Mod>;

mint dp[100005];
mint sum[100005];

int main() {
  fastio;
  ll ans = 0;
  ll N, K;
  cin >> N >> K;
  vector<pair<int, int>> v;
  rep(i, K) {
    int l, r;
    cin >> l >> r;
    v.push_back({l, r});
  }
  dp[1] = 1;
  sum[1] = 1;
  for (int i = 2; i <= N; ++i) {
    for (auto p : v) {
      int lpos = max(i - p.second - 1, 0);
      int rpos = max(i - p.first, 0);
      mint s = sum[rpos] - sum[lpos];
      dp[i] += s;
    }
    sum[i] += dp[i] + sum[i - 1];
  }
  cout << dp[N] << endl;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep1(i, n) for (ll i = 1; i <= n; ++i)
#define revrep(i, n) for (ll i = n - 1; i >= 0; --i)
inline constexpr ll Inf = (1ULL << 62) - 1;
#define fastio                                                                 \\
  cin.tie(nullptr);                                                            \\
  ios_base::sync_with_stdio(false);
#define endl '\\n'
template <class T> bool updmax(T &a, T b) {
  if (b > a) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool updmin(T &a, T b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}
template <class T> T permutation(ll n, ll k) {
  T f(1);
  for (ll i = 0; i < k; ++i, --n)
    f *= n;
  return f;
}
template <class T> T factorial(ll n) { return permutation<T>(n, n); }
template <class T> T binomial(ll n, ll k) {
  return permutation<T>(n, k) /= factorial<T>(k);
}

template <ll Mod> class modint {
public:
  ll n = 0;
  modint() {}
  modint(ll n) : n(n) { clamp(); }
  modint &operator=(modint const &a) = default;
  modint &operator=(int a) {
    n = a;
    clamp();
    return *this;
  }
  modint operator-() {
    modint t = *this;
    t.n = -t.n;
    t.clamp();
    return t;
  }
  modint &operator*=(modint const &a) {
    n *= a.n;
    clamp();
    return *this;
  }
  modint &operator*=(ll a) {
    n *= a;
    clamp();
    return *this;
  }
  modint &operator/=(modint const &a) {
    *this *= a.inv();
    return *this;
  }
  modint &operator+=(modint const &a) {
    n += a.n;
    if (n >= Mod)
      n -= Mod;
    return *this;
  }
  modint &operator-=(modint const &a) {
    n -= a.n;
    if (n < 0)
      n += Mod;
    return *this;
  }
  modint &operator%=(modint const &a) {
    n %= a.n;
    clamp();
    return *this;
  }
  friend modint operator*(modint a, modint b) {
    modint t(a);
    t.n *= b.n;
    t.clamp();
    return t;
  }
  friend modint operator+(modint a, modint b) {
    modint t(a);
    t.n += b.n;
    t.clamp();
    return t;
  }
  friend modint operator-(modint a, modint b) {
    modint t(a);
    t.n -= b.n;
    t.clamp();
    return t;
  }
  friend ostream &operator<<(ostream &os, modint const &a) {
    os << a.n;
    return os;
  }
  friend bool operator==(modint const &a, int b) { return a.n == b; }
  void clamp() {
    n %= Mod;
    if (n < 0)
      n += Mod;
  }
  modint inv() const { return this->pow(Mod - 2); }
  ll get() { return n; }
  modint pow(ll p) const {
    ll a = 1, e = n;
    while (p > 0) {
      if (p & 1) {
        a *= e;
        a %= Mod;
      }
      e *= e;
      e %= Mod;
      p >>= 1;
    }
    return modint(a);
  }
};

const ll Mod = 998244353;
using mint = modint<Mod>;

mint dp[200005];
mint sum[200005];

int main() {
  fastio;
  ll ans = 0;
  ll N, K;
  cin >> N >> K;
  vector<pair<int, int>> v;
  rep(i, K) {
    int l, r;
    cin >> l >> r;
    v.push_back({l, r});
  }
  dp[1] = 1;
  sum[1] = 1;
  for (int i = 2; i <= N; ++i) {
    for (auto p : v) {
      int lpos = max(i - p.second - 1, 0);
      int rpos = max(i - p.first, 0);
      mint s = sum[rpos] - sum[lpos];
      dp[i] += s;
    }
    sum[i] += dp[i] + sum[i - 1];
  }
  cout << dp[N] << endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 998244353;
// cout << setprecision(20) <<

int main() {
  ll n, k;
  cin >> n >> k;
  vector<pair<ll, ll>> v(k);
  for (int i = 0; i < k; ++i) {
    ll l, r;
    cin >> l >> r;
    v[i] = make_pair(l, r);
  }

  vector<ll> a(n + 1, 0);
  a[1] = 1;
  for (int i = 1; i < n; ++i) {
    // cout << "at i:" << i << endl;
    for (auto p : v) {
      for (int j = i + p.first; j <= min(i + p.second, n); ++j) {
        // cout << "j : " << j << endl;
        a[j] += a[i];
        a[j] %= MOD;
      }
    }
    // for (int j = 1; j <= n; ++j) {
    //     cout << a[j] << " ";
    // }
    // cout << endl;
  }
  cout << a[n] << endl;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 998244353;
// cout << setprecision(20) <<

#define SEG_LEN (200010)

ll seg[SEG_LEN * 2] = {0};

// one point
ll get(ll ind) {
  ind += SEG_LEN;
  ll sum = 0;
  sum += seg[ind];
  while (true) {
    ind /= 2;
    if (ind == 0)
      break;
    sum += seg[ind];
    sum %= MOD;
  }
  return sum;
}

// range
void add(ll l, ll r, ll x) {
  l += SEG_LEN;
  r += SEG_LEN;
  while (l < r) {
    if (l % 2 == 1) {
      seg[l] %= MOD;
      seg[l] += x;
      seg[l] %= MOD;
      l++;
    }
    l /= 2;
    if (r % 2 == 1) {
      seg[r - 1] %= MOD;
      seg[r - 1] += x;
      seg[r - 1] %= MOD;
      r--;
    }
    r /= 2;
  }
}

int main() {
  ll n, k;
  cin >> n >> k;
  vector<pair<ll, ll>> v(k);
  for (int i = 0; i < k; ++i) {
    ll l, r;
    cin >> l >> r;
    v[i] = make_pair(l, r);
  }

  add(1, 2, 1);
  for (int i = 1; i < n; ++i) {
    for (auto p : v) {
      ll x = get(i);
      ll l = p.first + i;
      if (l > n)
        continue;
      ll r = min(n + 1, p.second + i + 1);
      if (r - l <= 0)
        continue;
      add(l, r, x);
    }
  }
  // for (int i = 1; i <= n; ++i) {
  //   cout << get(i) << " ";
  // }
  // cout << endl;
  cout << get(n) << endl;
}


#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a), i##end = (b); i <= i##end; i++)
#define temT template <typename T>
using namespace std;
typedef long long ll;
const ll mo = 998244353;
const int N = int(2e5) + 10;

int n, K, a[11][2];

temT inline T add(T x, T y) { return (x += y, x >= mo) ? x -= mo : x; }
temT inline T dec(T x, T y) { return (x -= y, x < 0) ? x += mo : x; }
temT inline T mul(T x, T y) { return T((ll)x * y % mo); }

#define RT 1, 1, n
#define LS p << 1, l, mid
#define RS p << 1 | 1, mid + 1, r
int sum[N * 2], tag[N * 2];
void mt(int p) { sum[p] = add(sum[p << 1], sum[p << 1 | 1]); }
void fill(int p, int l, int r, int v) {
  sum[p] = add(sum[p], mul(r - l + 1, v));
  tag[p] = add(tag[p], v);
}
void pd(int p, int l, int r) {
  int mid = (l + r) >> 1;
  fill(LS, tag[p]);
  fill(RS, tag[p]);
  tag[p] = 0;
}
void upd(int p, int l, int r, int el, int er, int v) {
  if (el <= l && r <= er)
    return fill(p, l, r, v), void();
  pd(p, l, r);
  int mid = (l + r) >> 1;
  if (el <= mid)
    upd(LS, el, er, v);
  if (er >= mid + 1)
    upd(RS, el, er, v);
  mt(p);
}
int ask(int p, int l, int r, int ep) {
  if (l == r)
    return sum[p];
  pd(p, l, r);
  int mid = (l + r) >> 1;
  if (ep <= mid)
    return ask(LS, ep);
  if (ep >= mid + 1)
    return ask(RS, ep);
}

int main() {
  cin >> n >> K;
  FOR(i, 1, K) cin >> a[i][0] >> a[i][1];
  upd(RT, 1, 1, 1);
  FOR(i, 1, n - 1) {
    int x = ask(RT, i);
    FOR(j, 1, K) {
      int l = i + a[j][0], r = i + a[j][1];
      if (l > n)
        continue;
      l = min(l, n), r = min(r, n);
      upd(RT, l, r, x);
    }
  }
  cout << ask(RT, n);
  return 0;
}

#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a), i##end = (b); i <= i##end; i++)
#define temT template <typename T>
using namespace std;
typedef long long ll;
const ll mo = 998244353;
const int N = int(2e5) + 10;

int n, K, a[11][2];

temT inline T add(T x, T y) { return (x += y, x >= mo) ? x -= mo : x; }
temT inline T dec(T x, T y) { return (x -= y, x < 0) ? x += mo : x; }
temT inline T mul(T x, T y) { return T((ll)x * y % mo); }

#define RT 1, 1, n
#define LS p << 1, l, mid
#define RS p << 1 | 1, mid + 1, r
int sum[N * 4], tag[N * 4];
void mt(int p) { sum[p] = add(sum[p << 1], sum[p << 1 | 1]); }
void fill(int p, int l, int r, int v) {
  sum[p] = add(sum[p], mul(r - l + 1, v));
  tag[p] = add(tag[p], v);
}
void pd(int p, int l, int r) {
  int mid = (l + r) >> 1;
  fill(LS, tag[p]);
  fill(RS, tag[p]);
  tag[p] = 0;
}
void upd(int p, int l, int r, int el, int er, int v) {
  if (el <= l && r <= er)
    return fill(p, l, r, v), void();
  pd(p, l, r);
  int mid = (l + r) >> 1;
  if (el <= mid)
    upd(LS, el, er, v);
  if (er >= mid + 1)
    upd(RS, el, er, v);
  mt(p);
}
int ask(int p, int l, int r, int ep) {
  if (l == r)
    return sum[p];
  pd(p, l, r);
  int mid = (l + r) >> 1;
  if (ep <= mid)
    return ask(LS, ep);
  if (ep >= mid + 1)
    return ask(RS, ep);
}

int main() {
  cin >> n >> K;
  FOR(i, 1, K) cin >> a[i][0] >> a[i][1];
  upd(RT, 1, 1, 1);
  FOR(i, 1, n - 1) {
    int x = ask(RT, i);
    FOR(j, 1, K) {
      int l = i + a[j][0], r = i + a[j][1];
      if (l > n)
        continue;
      l = min(l, n), r = min(r, n);
      upd(RT, l, r, x);
    }
  }
  cout << ask(RT, n);
  return 0;
}


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

// 入力
template <typename T> istream &operator>>(istream &is, vector<T> &a) {
  for (int i = 0; i < a.size(); i++)
    is >> a[i];
  return is;
}
template <typename T, typename U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.first >> p.second;
  return is;
}

// 出力
template <typename T> ostream &operator<<(ostream &os, const vector<T> &a) {
  for (int i = 0; i < a.size(); i++) {
    os << a[i] << ((i + 1 != a.size()) ? " " : "");
  }
  return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.first << " " << p.second;
  return os;
}

// 入出力高速化
struct hishimochi {
  hishimochi() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
  }
};
hishimochi Hishimochi;

// 辺
struct edge {
  long long to, cost;
  edge(long long t, long long c) : to(t), cost(c) {}
};
struct edge2 {
  long long from, to, cost;
  edge2(long long f, long long t, long long c) : from(f), to(t), cost(c) {}
};

// 型名
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pll = pair<long long, long long>;
using vl = vector<long long>;
using vvl = vector<vector<long long>>;
using vvvl = vector<vector<vector<long long>>>;
using vc = vector<char>;
using vvc = vector<vector<char>>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vp = vector<pair<long long, long long>>;
using Lqueue = priority_queue<long long>;
using Squeue = priority_queue<long long, vector<long long>, greater<long long>>;

// 定数
const int MOD1 = 1000000007;
const int MOD2 = 998244353;
const long double PI = 3.1415926535897932;
const long long MAXLL = 9223372036854775807;
const int MAXI = 2147483647;
const long long INF = 2305843009213693951;
const int inf = 1073741789;
const long double eps = 0.000000001;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int dy[] = {1, 0, -1, 0, 1, 1, -1, -1};

// マクロ
#define overload3(_1, _2, _3, name, ...) name
#define rep1(n) for (int _ = 0; _ < (n); _++)
#define rep2(i, n) for (int i = 0; i < (n); i++)
#define rep3(i, s, n) for (long long i = (s); i < (n); i++)
#define rep(...) overload3(__VA_ARGS__, rep3, rep2, rep1)(__VA_ARGS__)
#define bitrep1(n) for (int _ = 0; _ < (1LL << (n)); _++)
#define bitrep2(i, n) for (int i = 0; i < (1LL << (n)); i++)
#define bitrep3(i, s, n) for (int i = (s); i < (1LL << (n)); i++)
#define bitrep(...)                                                            \\
  overload3(__VA_ARGS__, bitrep3, bitrep2, bitrep1)(__VA_ARGS__)
#define rrep0(n) for (int i = (n)-1; i >= 0; i--)
#define rrep1(i, n) for (int i = (n)-1; i >= 0; i--)
#define rrep2(i, s, n) for (long long i = (n - 1); i >= (s); i--)
#define rrep(...) overload3(__VA_ARGS__, rrep2, rrep1, rrep0)(__VA_ARGS__)
#define rbf(a, x) for (auto &a : x)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define bitcheck(bit, i) (bit) & (1LL << (i))
#define Maxe(x) *max_element((x).begin(), (x).end())
#define Mine(x) *min_element((x).begin(), (x).end())
#define Sume(x) accumulate((x).begin(), (x).end(), 0LL)
#define Size(x) ((long long)(x).size())
#define Sort(x) sort((x).begin(), (x).end())
#define rSort(x) sort((x).rbegin(), (x).rend())
#define Rev(x) reverse((x).begin(), (x).end())
#define Lin(s) getline(cin, (s))

// 省略
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define eb emplace_back

// 関数
void Yes(bool a) { cout << (a ? "Yes" : "No") << endl; }
void YES(bool a) { cout << (a ? "YES" : "NO") << endl; }
long long modpow(long long x, long long n, int m) {
  long long r = 1;
  while (n > 0) {
    if (n & 1)
      (r *= x) %= m;
    (x *= x) %= m;
    n >>= 1;
  }
  return r;
}
long long Gcd(long long a, long long b) { return b ? Gcd(b, a % b) : a; }
long long Lcm(long long a, long long b) { return a / Gcd(a, b) * b; }
inline long long cutup(long long a, long long b) { return (a + b - 1) / b; }
inline long long popcnt(long long a) { return __builtin_popcountll(a); }
template <class T, class U> auto max(T a, U b) { return a > b ? a : b; }
template <class T, class U> auto min(T a, U b) { return a < b ? a : b; }
template <class T, class U> inline bool chmin(T &a, U b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T, class U> inline bool chmax(T &a, U b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> void print(T a) { cout << a << endl; }
template <class t> t mypow(t a, long long b) {
  if (b == 0)
    return 1;
  if (a == 0)
    return 0;
  t x = 1;
  while (b > 0) {
    if (b & 1LL)
      x *= a;
    a *= a;
    b >>= 1LL;
  }
  return x;
}

// MODint
template <long long MOD> struct Fp {
  long long val;
  constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
    if (val < 0)
      val += MOD;
  }
  constexpr long long getmod() { return MOD; }
  constexpr Fp operator-() const noexcept { return val ? MOD - val : 0; }
  constexpr Fp operator+(const Fp &r) const noexcept { return Fp(*this) += r; }
  constexpr Fp operator-(const Fp &r) const noexcept { return Fp(*this) -= r; }
  constexpr Fp operator*(const Fp &r) const noexcept { return Fp(*this) *= r; }
  constexpr Fp operator/(const Fp &r) const noexcept { return Fp(*this) /= r; }
  constexpr Fp &operator+=(const Fp &r) noexcept {
    val += r.val;
    if (val >= MOD)
      val -= MOD;
    return *this;
  }
  constexpr Fp &operator-=(const Fp &r) noexcept {
    val -= r.val;
    if (val < 0)
      val += MOD;
    return *this;
  }
  constexpr Fp &operator*=(const Fp &r) noexcept {
    val = val * r.val % MOD;
    return *this;
  }
  constexpr Fp &operator/=(const Fp &r) noexcept {
    long long a = r.val, b = MOD, u = 1, v = 0;
    while (b) {
      long long t = a / b;
      a -= t * b;
      swap(a, b);
      u -= t * v;
      swap(u, v);
    }
    val = val * u % MOD;
    if (val < 0)
      val += MOD;
    return *this;
  }
  constexpr bool operator==(const Fp &r) const noexcept {
    return this->val == r.val;
  }
  constexpr bool operator!=(const Fp &r) const noexcept {
    return this->val != r.val;
  }
  friend constexpr ostream &operator<<(ostream &os, const Fp<MOD> &x) noexcept {
    return os << x.val;
  }

  friend constexpr istream &operator>>(istream &is, Fp<MOD> &x) {
    long long t;
    is >> t;
    x = t;
    return (is);
  }
};
using mint = Fp<MOD2>;

signed main() {
  ll n, k;
  cin >> n >> k;
  vector<mint> DP(n, 0);
  DP[0] = 1;
  vl S;
  rep(k) {
    ll l, r;
    cin >> l >> r;
    rep(i, l, r + 1) { S.emplace_back(i); }
  }
  Sort(S);
  rep(i, n) {
    rep(j, Size(S)) {
      if (S[j] + i > n - 1)
        break;
      DP[S[j] + i] += DP[i];
    }
  }
  cout << DP[n - 1] << endl;
}

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

// 入力
template <typename T> istream &operator>>(istream &is, vector<T> &a) {
  for (int i = 0; i < a.size(); i++)
    is >> a[i];
  return is;
}
template <typename T, typename U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.first >> p.second;
  return is;
}

// 出力
template <typename T> ostream &operator<<(ostream &os, const vector<T> &a) {
  for (int i = 0; i < a.size(); i++) {
    os << a[i] << ((i + 1 != a.size()) ? " " : "");
  }
  return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.first << " " << p.second;
  return os;
}

// 入出力高速化
struct hishimochi {
  hishimochi() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
  }
};
hishimochi Hishimochi;

// 辺
struct edge {
  long long to, cost;
  edge(long long t, long long c) : to(t), cost(c) {}
};
struct edge2 {
  long long from, to, cost;
  edge2(long long f, long long t, long long c) : from(f), to(t), cost(c) {}
};

// 型名
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pll = pair<long long, long long>;
using vl = vector<long long>;
using vvl = vector<vector<long long>>;
using vvvl = vector<vector<vector<long long>>>;
using vc = vector<char>;
using vvc = vector<vector<char>>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vp = vector<pair<long long, long long>>;
using Lqueue = priority_queue<long long>;
using Squeue = priority_queue<long long, vector<long long>, greater<long long>>;

// 定数
const int MOD1 = 1000000007;
const int MOD2 = 998244353;
const long double PI = 3.1415926535897932;
const long long MAXLL = 9223372036854775807;
const int MAXI = 2147483647;
const long long INF = 2305843009213693951;
const int inf = 1073741789;
const long double eps = 0.000000001;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int dy[] = {1, 0, -1, 0, 1, 1, -1, -1};

// マクロ
#define overload3(_1, _2, _3, name, ...) name
#define rep1(n) for (int _ = 0; _ < (n); _++)
#define rep2(i, n) for (int i = 0; i < (n); i++)
#define rep3(i, s, n) for (long long i = (s); i < (n); i++)
#define rep(...) overload3(__VA_ARGS__, rep3, rep2, rep1)(__VA_ARGS__)
#define bitrep1(n) for (int _ = 0; _ < (1LL << (n)); _++)
#define bitrep2(i, n) for (int i = 0; i < (1LL << (n)); i++)
#define bitrep3(i, s, n) for (int i = (s); i < (1LL << (n)); i++)
#define bitrep(...)                                                            \\
  overload3(__VA_ARGS__, bitrep3, bitrep2, bitrep1)(__VA_ARGS__)
#define rrep0(n) for (int i = (n)-1; i >= 0; i--)
#define rrep1(i, n) for (int i = (n)-1; i >= 0; i--)
#define rrep2(i, s, n) for (long long i = (n - 1); i >= (s); i--)
#define rrep(...) overload3(__VA_ARGS__, rrep2, rrep1, rrep0)(__VA_ARGS__)
#define rbf(a, x) for (auto &a : x)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define bitcheck(bit, i) (bit) & (1LL << (i))
#define Maxe(x) *max_element((x).begin(), (x).end())
#define Mine(x) *min_element((x).begin(), (x).end())
#define Sume(x) accumulate((x).begin(), (x).end(), 0LL)
#define Size(x) ((long long)(x).size())
#define Sort(x) sort((x).begin(), (x).end())
#define rSort(x) sort((x).rbegin(), (x).rend())
#define Rev(x) reverse((x).begin(), (x).end())
#define Lin(s) getline(cin, (s))

// 省略
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define eb emplace_back

// 関数
void Yes(bool a) { cout << (a ? "Yes" : "No") << endl; }
void YES(bool a) { cout << (a ? "YES" : "NO") << endl; }
long long modpow(long long x, long long n, int m) {
  long long r = 1;
  while (n > 0) {
    if (n & 1)
      (r *= x) %= m;
    (x *= x) %= m;
    n >>= 1;
  }
  return r;
}
long long Gcd(long long a, long long b) { return b ? Gcd(b, a % b) : a; }
long long Lcm(long long a, long long b) { return a / Gcd(a, b) * b; }
inline long long cutup(long long a, long long b) { return (a + b - 1) / b; }
inline long long popcnt(long long a) { return __builtin_popcountll(a); }
template <class T, class U> auto max(T a, U b) { return a > b ? a : b; }
template <class T, class U> auto min(T a, U b) { return a < b ? a : b; }
template <class T, class U> inline bool chmin(T &a, U b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T, class U> inline bool chmax(T &a, U b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> void print(T a) { cout << a << endl; }
template <class t> t mypow(t a, long long b) {
  if (b == 0)
    return 1;
  if (a == 0)
    return 0;
  t x = 1;
  while (b > 0) {
    if (b & 1LL)
      x *= a;
    a *= a;
    b >>= 1LL;
  }
  return x;
}

/* BIT: RAQ対応BIT
    初期値は a_1 = a_2 = ... = a_n = 0
    ・add(l,r,x): [l,r) に x を加算する
    ・sum(i): a_1 + a_2 + ... + a_i を計算する
    計算量は全て O(logn)
*/
template <typename T> struct BIT {
  int n;            // 要素数
  vector<T> bit[2]; // データの格納先
  BIT(int n_) { init(n_); }
  void init(int n_) {
    n = n_ + 1;
    for (int p = 0; p < 2; p++)
      bit[p].assign(n, 0);
  }

  void add_sub(int p, int i, T x) {
    for (int idx = i; idx < n; idx += (idx & -idx)) {
      bit[p][idx] += x;
    }
  }
  void add(int l, int r, T x) { // [l,r) に加算
    add_sub(0, l, -x * (l - 1));
    add_sub(0, r, x * (r - 1));
    add_sub(1, l, x);
    add_sub(1, r, -x);
  }

  T sum_sub(int p, int i) {
    T s(0);
    for (int idx = i; idx > 0; idx -= (idx & -idx)) {
      s += bit[p][idx];
    }
    return s;
  }
  T sum(int i) { return sum_sub(0, i) + sum_sub(1, i) * i; }
};

// MODint
template <long long MOD> struct Fp {
  long long val;
  constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
    if (val < 0)
      val += MOD;
  }
  constexpr long long getmod() { return MOD; }
  constexpr Fp operator-() const noexcept { return val ? MOD - val : 0; }
  constexpr Fp operator+(const Fp &r) const noexcept { return Fp(*this) += r; }
  constexpr Fp operator-(const Fp &r) const noexcept { return Fp(*this) -= r; }
  constexpr Fp operator*(const Fp &r) const noexcept { return Fp(*this) *= r; }
  constexpr Fp operator/(const Fp &r) const noexcept { return Fp(*this) /= r; }
  constexpr Fp &operator+=(const Fp &r) noexcept {
    val += r.val;
    if (val >= MOD)
      val -= MOD;
    return *this;
  }
  constexpr Fp &operator-=(const Fp &r) noexcept {
    val -= r.val;
    if (val < 0)
      val += MOD;
    return *this;
  }
  constexpr Fp &operator*=(const Fp &r) noexcept {
    val = val * r.val % MOD;
    return *this;
  }
  constexpr Fp &operator/=(const Fp &r) noexcept {
    long long a = r.val, b = MOD, u = 1, v = 0;
    while (b) {
      long long t = a / b;
      a -= t * b;
      swap(a, b);
      u -= t * v;
      swap(u, v);
    }
    val = val * u % MOD;
    if (val < 0)
      val += MOD;
    return *this;
  }
  constexpr bool operator==(const Fp &r) const noexcept {
    return this->val == r.val;
  }
  constexpr bool operator!=(const Fp &r) const noexcept {
    return this->val != r.val;
  }
  friend constexpr ostream &operator<<(ostream &os, const Fp<MOD> &x) noexcept {
    return os << x.val;
  }

  friend constexpr istream &operator>>(istream &is, Fp<MOD> &x) {
    long long t;
    is >> t;
    x = t;
    return (is);
  }
};
using mint = Fp<MOD2>;

signed main() {
  ll n, k;
  cin >> n >> k;
  vl l(k), r(k);
  rep(i, k) cin >> l[i] >> r[i];
  BIT<mint> B(n);
  B.add(1, 2, 1);
  rep(i, 1, n) {
    mint c = B.sum(i);
    if (i)
      c -= B.sum(i - 1);
    rep(j, k) { B.add(l[j] + i, min(r[j] + 1 + i, n + 1), c); }
  }
  print(B.sum(n) - B.sum(n - 1));
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
int main() {
  ll n, k;
  cin >> n >> k;
  vector<pair<ll, ll>> data(k);
  for (ll i = 0; i < k; i++) {
    ll l, r;
    cin >> l >> r;
    r -= l;
    data[i] = {l, r};
  }
  vector<ll> dp(2e5 + 20, 0);
  dp[1] = 1;
  for (ll i = 1; i < 2e5; i++) {
    if (dp[i] == 0)
      continue;
    for (ll j = 0; j < k; j++) {
      for (ll l = 0; l <= data[j].second; l++) {
        if (i + data[j].first + l >= 2e5)
          break;
        dp[i + data[j].first + l] = (dp[i + data[j].first + l] + dp[i]) % MOD;
      }
    }
  }
  cout << dp[n] << endl;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> l(k), r(k);
  for (ll i = 0; i < k; i++)
    cin >> l[i] >> r[i];
  vector<ll> dp(2e5 + 20, 0);
  vector<ll> sum(2e5 + 20, 0);
  sum[1] = 1;
  dp[1] = 1;
  for (ll i = 2; i <= n; i++) {
    for (ll j = 0; j < k; j++) {
      ll li = i - r[j];
      ll ri = i - l[j];
      if (ri < 0)
        continue;
      li = max(li, (ll)1);
      dp[i] += (sum[ri] - sum[li - 1] + MOD);
      dp[i] %= MOD;
    }
    sum[i] = sum[i - 1] + dp[i];
    sum[i] %= MOD;
  }
  cout << dp[n] << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define INF 999999999
#define rep(i, n) for (int i = 0; i < n; i++)
const ll MOD = 1000000007;
ll cnt = 0, ans = 0;
const int MAX = 510000;

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

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

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

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

      li = max(li, 1);
      ri = max(ri, 1);
      dp[i] += dpsum[ri] - dpsum[li - 1];
    }
    dpsum[i] = dpsum[i - 1] + dp[i];
  }
  cout << dp[n] << endl;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define INF 999999999
#define rep(i, n) for (int i = 0; i < n; i++)
const ll MOD = 1000000007;
ll cnt = 0, ans = 0;
const int MAX = 510000;

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

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

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

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

      li = max(li, 1);
      if (ri < 0)
        continue;
      dp[i] += dpsum[ri] - dpsum[li - 1];
    }
    dpsum[i] = dpsum[i - 1] + dp[i];
  }
  cout << dp[n] << endl;
}

Fatal glibc error: malloc assertion failure in sysmalloc: (old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)


/*It is better to taste failure
          than to regret*/

#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <ratio>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;

typedef long long ll;
typedef long double LD;
#define int ll
#define double LD
#define pb push_back
#define mp make_pair
#define REP(i, n) for (int i = 0; i < n; i++)
#define loop(i, n) for (int i = 0; i < n; i++)
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define REPD(i, n) for (int i = n - 1; i >= 0; i--)
#define FORD(i, a, b) for (int i = a; i >= b; i--)
#define remax(a, b) a = max(a, b)
#define remin(a, b) a = min(a, b)
#define mem(a, b) memset(a, b, sizeof a)
#define append push_back
#define all(v) v.begin(), v.end()
#define F first
#define S second
#define print(x) cout << (x) << endl
#define PRECISION(x) cout << fixed << setprecision(x)
#define FAST_IO                                                                \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define Test()                                                                 \\
  {                                                                            \\
    int t;                                                                     \\
    cin >> t;                                                                  \\
    for (int i = 1; i <= t; i++) {                                             \\
      cout << "Case #" << i << ": ";                                           \\
      solve();                                                                 \\
    }                                                                          \\
  }
#define test()                                                                 \\
  {                                                                            \\
    int t;                                                                     \\
    cin >> t;                                                                  \\
    for (int i = 1; i <= t; i++) {                                             \\
      solve();                                                                 \\
    }                                                                          \\
  }
#define vi vector<int>
#define vii vector<pair<int, int>>
#define vci vector<pair<char, int>>
#define vic vector<pair<int, char>>
#define N 200005
#define pb push_back
const double PI = acos(-1);
const int MOD = 1000000007;
const int FMOD = 998244353;

int dp[N];
int n, k;
map<int, int> mp1;
int solve(int start, vi &v) {
  if (start > n) {
    return 0;
  }

  if (start == n) {
    return 1;
  }
  if (dp[start] != -1)
    return dp[start];

  int ans = 0;
  int size = v.size();
  for (int i = 0; i < size; i++) {
    ans = (ans % FMOD + solve(start + v[i], v) % FMOD) % FMOD;
  }
  return dp[start] = ans;
}
void solve() {

  cin >> n >> k;

  set<int> st;
  loop(i, k) {
    int x, y;
    cin >> x >> y;

    for (int j = x; j <= y; j++)
      st.insert(j);
  }

  vi v;
  for (auto x : st)
    v.pb(x);

  mem(dp, -1);
  cout << solve(1, v) << endl;
}
signed main() {
  FAST_IO;

  // test();
  solve();
}

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

/*

*/

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

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

  sort(l.begin(), l.end());
  sort(r.begin(), r.end());
  ll mod = 998244353;
  vector<ll> res(n, 0);
  res[0] = 1;

  vector<ll> sd(k, 0);
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < k; j++) {
      if (i - l[j] < 0)
        continue;

      if (i - r[j] > 0) {
        sd[j] += res[i - l[j]];
        sd[j] -= res[i - r[j] - 1];

      } else {
        sd[j] += res[i - l[j]];
      }
      // if( i == 1 && j ==

      sd[j] += mod;
      sd[j] %= mod;
      res[i] += sd[j];
      res[i] %= mod;
    }
  }

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int t;
  t = 1;
  // cin >> t;
  while (t--)
    test_case();
  return 0;
}


#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

ll solve(ll loc, vector<ll> &pattern, vector<ll> action) {
  ll cnt(0);

  if (loc == 1) {
    return 1;
  }
  if (pattern[loc] == -1) {
    for (ll i = 0; i < action.size(); ++i) {
      if (loc - action[i] > 0) {
        cnt += (solve(loc - action[i], pattern, action) % 998244353);
        cnt %= 998244353;
      }
    }
    pattern[loc] = cnt;
    return cnt;
  } else {
    return pattern[loc];
  }
}

int main() {
  ll N;
  ll K;
  ll cnt(0);
  cin >> N >> K;
  ll L[K];
  ll R[K];

  for (int i = 0; i < K; ++i) {
    cin >> L[i] >> R[i];
  }

  vector<ll> pattern_map(N, -1);
  vector<ll> fill_map(N + 1, -1);
  vector<ll> action_map;

  for (int i = 0; i < K; i++) {
    for (int j = L[i]; j <= R[i]; j++) {
      if (fill_map[j] == -1) {
        action_map.push_back(j);
        fill_map[j] = 0;
      }
    }
  }
  for (ll i = 0; i < action_map.size(); ++i) {
    if (N - action_map[i] > 0) {
      cnt += (solve(N - action_map[i], pattern_map, action_map) % 998244353);
      cnt %= 998244353;
    }
  }
  cout << cnt % 998244353 << endl;

  return 0;
}

#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

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

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

int main() {
  ll N;
  ll K;
  cin >> N >> K;
  ll L[K];
  ll R[K];
  for (int i = 0; i < K; i++) {
    cin >> L[i] >> R[i];
  }

  vector<mint> dp(N + 1, 0);
  vector<mint> acc_sum(N + 1, 0);

  dp[1] = 1;
  acc_sum[1] = 1;

  for (int i = 2; i <= N; ++i) {
    for (int j = 0; j < K; j++) {
      int rj = i - L[j];
      int lj = i - R[j];
      if (rj < 0)
        continue;
      lj = max(lj, 1);
      dp[i] += (acc_sum[rj] - acc_sum[lj - 1]);
    }
    acc_sum[i] = (acc_sum[i - 1] + dp[i]);
  }
  cout << dp[N] << endl;
  return 0;
}


#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
constexpr ll MOD = 998244353;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> l(k), r(k);
  vector<ll> ans(n + 10, 0);
  for (int i = 0; i < k; i++) {
    cin >> l[i] >> r[i];
  }
  ans[0] = 1;
  ll now = 0;
  for (int i = 0; i < n; i++) {
    now += ans[i];
    if (now > 0) {
      for (int j = 0; j < k; j++) {
        ans[l[j] + i] += now;
        ans[min(r[j] + i + 1, n)] -= now;
      }
    }
    ans[i] %= MOD;
    // for(int j = 0; j < n; j++) {
    //   cout << ans[j] << " ";
    // }
    // cout << '\\n';
  }
  cout << ans[n - 1] % MOD << endl;
  return 0;
}

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
constexpr ll MOD = 998244353;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> l(k), r(k);
  vector<ll> ans(n + 10, 0), sum(n + 10, 0);
  for (int i = 0; i < k; i++) {
    cin >> l[i] >> r[i];
  }
  ans[0] = 1;
  sum[0] = 1;
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < k; j++) {
      if (i - r[j] - 1 >= 0) {
        ans[i] -= sum[i - r[j] - 1];
      }
      if (i - l[j] >= 0) {
        ans[i] += sum[i - l[j]];
      }
    }
    ans[i] %= MOD;
    sum[i] += sum[i - 1] + ans[i];
    // for(int j = 0; j < n; j++) {
    //   cout << ans[j] << " ";
    // }
    // cout << '\\n';
  }
  if (ans[n - 1] < 0) {
    ans[n - 1] += MOD;
  }
  cout << ans[n - 1] % MOD << endl;
  return 0;
}


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

#define rep(i, a, b) for (int i = (a); i < (b); i++)

using ll = long long;
const ll mod = 998244353;

ll modpow(ll a, ll b) {
  if (b == 0)
    return 1;
  return modpow(a * a % mod, b / 2) * (b % 2 ? a : 1) % mod;
}

struct SegTree {
  int n;
  vector<ll> node, lazy;

  SegTree(int sz) {
    n = 1;
    while (n < sz)
      n *= 2;
    node.resize(2 * n - 1);
    lazy.resize(2 * n - 1);
  }

  void eval(int k, int l, int r) {
    if (lazy[k] != 0) {
      (node[k] += lazy[k]) %= mod;

      if (r - l > 1) {
        (lazy[2 * k + 1] += lazy[k] * modpow(2, mod - 2) % mod) %= mod;
        (lazy[2 * k + 2] += lazy[k] * modpow(2, mod - 2) % mod) %= mod;
      }

      lazy[k] = 0;
    }
  }

  void add(int a, int b, ll x, int k = 0, int l = 0, int r = -1) {
    if (r < 0)
      r = n;
    eval(k, l, r);

    if (b <= l or r <= a)
      return;
    if (a <= l and r <= b) {
      (lazy[k] += (r - l) * x % mod) %= mod;
      eval(k, l, r);
    } else {
      add(a, b, x, 2 * k + 1, l, (l + r) / 2);
      add(a, b, x, 2 * k + 2, (l + r) / 2, r);
      node[k] = (node[2 * k + 1] + node[2 * k + 2]) % mod;
    }
  }

  ll get(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r < 0)
      r = n;
    if (b <= l or r <= a)
      return 0;

    eval(k, l, r);
    if (a <= l and r <= b)
      return node[k];
    ll vl = get(a, b, 2 * k + 1, l, (l + r) / 2);
    ll vr = get(a, b, 2 * k + 2, (l + r) / 2, r);
    return (vl + vr) % mod;
  }
};

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

  vector<int> l(n), r(n);
  rep(i, 0, k) cin >> l[i] >> r[i];

  SegTree st(n);
  st.add(0, 1, 1);
  rep(i, 0, n) {
    rep(j, 0, k) { st.add(i + l[j], min(n, i + r[j] + 1), st.get(i, i + 1)); }
  }

  cout << st.get(n - 1, n) << endl;

  // rep(i, 0, n) cout << st.get(i, i + 1) << " ";
  // // cout << endl;

  return 0;
}

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

#define rep(i, a, b) for (int i = (a); i < (b); i++)

using ll = long long;
const ll mod = 998244353;

ll inv2;
ll modpow(ll a, ll b) {
  if (b == 0)
    return 1;
  return modpow(a * a % mod, b / 2) * (b % 2 ? a : 1) % mod;
}

struct SegTree {
  int n;
  vector<ll> node, lazy;

  SegTree(int sz) {
    n = 1;
    while (n < sz)
      n *= 2;
    node.resize(2 * n - 1);
    lazy.resize(2 * n - 1);
  }

  void eval(int k, int l, int r) {
    if (lazy[k] != 0) {
      (node[k] += lazy[k]) %= mod;

      if (r - l > 1) {
        (lazy[2 * k + 1] += lazy[k] * inv2 % mod) %= mod;
        (lazy[2 * k + 2] += lazy[k] * inv2 % mod) %= mod;
      }

      lazy[k] = 0;
    }
  }

  void add(int a, int b, ll x, int k = 0, int l = 0, int r = -1) {
    if (r < 0)
      r = n;
    eval(k, l, r);

    if (b <= l or r <= a)
      return;
    if (a <= l and r <= b) {
      (lazy[k] += (r - l) * x % mod) %= mod;
      eval(k, l, r);
    } else {
      add(a, b, x, 2 * k + 1, l, (l + r) / 2);
      add(a, b, x, 2 * k + 2, (l + r) / 2, r);
      node[k] = (node[2 * k + 1] + node[2 * k + 2]) % mod;
    }
  }

  ll get(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r < 0)
      r = n;
    if (b <= l or r <= a)
      return 0;

    eval(k, l, r);
    if (a <= l and r <= b)
      return node[k];
    ll vl = get(a, b, 2 * k + 1, l, (l + r) / 2);
    ll vr = get(a, b, 2 * k + 2, (l + r) / 2, r);
    return (vl + vr) % mod;
  }
};

int main() {
  inv2 = modpow(2, mod - 2);

  int n, k;
  cin >> n >> k;

  vector<int> l(n), r(n);
  rep(i, 0, k) cin >> l[i] >> r[i];

  SegTree st(n);
  st.add(0, 1, 1);
  rep(i, 0, n) {
    rep(j, 0, k) { st.add(i + l[j], min(n, i + r[j] + 1), st.get(i, i + 1)); }
  }

  cout << st.get(n - 1, n) << endl;

  // rep(i, 0, n) cout << st.get(i, i + 1) << " ";
  // // cout << endl;

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int)x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9 + 7;
const ll INF = 2e15;
template <class T> void print(const T &t) { cout << t << endl; }
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

int main() {
  ll n, k;
  cin >> n >> k;
  ll mod = 998244353;
  vl s(0);
  rep(i, k) {
    ll l, r;
    cin >> l >> r;
    for (ll i = l; i <= r; i++) {
      s.pb(i);
    }
  }
  sort(all(s));
  vl dp(n + 1, 0);
  dp[1] = 1;
  for (ll i = 1; i <= n; i++) {
    for (ll j = 0; j < sz(s); j++) {
      if (i - s[j] < 0) {
        break;
      }
      dp[i] += dp[i - s[j]];
      dp[i] %= mod;
    }
  }
  print(dp[n]);
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int)x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9 + 7;
const ll INF = 2e15;
template <class T> void print(const T &t) { cout << t << endl; }
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

int main() {
  ll n, k;
  cin >> n >> k;
  ll mod = 998244353;
  vector<Pll> s(0);
  rep(i, k) {
    ll l, r;
    cin >> l >> r;
    s.pb(mp(l, r));
  }
  vl dp(n + 1, 0);
  dp[1] = 1;
  dp[2] = -1;
  for (ll i = 1; i <= n; i++) {
    dp[i] += dp[i - 1];
    dp[i] %= mod;
    for (ll j = 0; j < k; j++) {
      if (i + s[j].F <= n) {
        dp[i + s[j].F] += dp[i];
      }
      if (i + s[j].S + 1 <= n) {
        dp[i + s[j].S + 1] -= dp[i];
      }
    }
  }
  dp[n] %= mod;
  dp[n] = (dp[n] + mod) % mod;
  print(dp[n]);
}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <iostream>
using namespace std;

// #define int long long int
#define all(x) (x).begin(), (x).end()
#define removeDuplicates(a) a.resize(unique(all(a)) - a.begin())
#define endl '\\n'

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

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

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

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

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

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

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

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

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

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

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

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

private:
  Type value;
};

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

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

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

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

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

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

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

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

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

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

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

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

/*
using ModType = int;

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

constexpr int md = 998244353;
using Mint = Modular<std::integral_constant<decay<decltype(md)>::type, md>>;
// remember to comment out #define int long long int

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

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

void solve() {
  int n, k;
  cin >> n >> k;
  vector<int> values;
  for (int i = 0; i < k; i++) {
    int u, v;
    cin >> u >> v;
    for (int j = u; j <= v; j++) {
      values.push_back(j);
    }
  }
  sort(all(values));
  vector<Mint> dp(n + 1);
  dp[1] = 1;
  for (int i = 1; i <= n; i++) {
    if (dp[i] == 0) {
      continue;
    }
    for (int d : values) {
      if (i + d > n) {
        break;
      }
      dp[i + d] += dp[i];
    }
  }
  cout << dp[n] << endl;
}

int32_t main() {

  // remove for interactive problems
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  solve();
  cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC
       << "ms\\n";

  return 0;
}

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <iostream>
using namespace std;

#define int long long int
#define all(x) (x).begin(), (x).end()
#define removeDuplicates(a) a.resize(unique(all(a)) - a.begin())
#define endl '\\n'

const int mod = 998244353;

class segtree {
  int sz;
  vector<int> adds;
  vector<int> cnt;

public:
  segtree(int n) {
    sz = 1;
    while (sz < n) {
      sz = sz * 2;
    }
    adds.assign(2 * sz, 0LL);
    cnt.assign(2 * sz, 0LL);
  }
  void make(int l, int r, int v, int start, int left, int right) {
    if (left >= r || right <= l) {
      return;
    }
    if (left >= l && right <= r) {
      adds[start] = (adds[start] + v) % mod;
      return;
    }
    int mid = (left + right) / 2;
    make(l, r, v, 2 * start + 1, left, mid);
    make(l, r, v, 2 * start + 2, mid, right);
  }
  void make(int l, int r, int v) { make(l, r, v, 0, 0, sz); }
  int val(int i, int v, int start, int left, int right) {
    if (right - left == 1) {
      return (v + adds[start]) % mod;
    }
    int mid = (left + right) / 2;
    int num = (v + adds[start]) % mod;
    if (i < mid) {
      return val(i, num, 2 * start + 1, left, mid) % mod;
    } else {
      return val(i, num, 2 * start + 2, mid, right) % mod;
    }
  }
  int val(int i) { return val(i, 0, 0, 0, sz) % mod; }
};

void solve() {
  int n, k;
  cin >> n >> k;
  segtree st(n);
  vector<pair<int, int>> ranges;
  for (int j = 0; j < k; j++) {
    int u, v;
    cin >> u >> v;
    u--;
    ranges.push_back({u, v});
  }
  sort(all(ranges));
  for (pair<int, int> p : ranges) {
    st.make(p.first + 1, min(p.second + 1, n), 1);
  }
  for (int i = 1; i < n; i++) {
    int a = st.val(i);
    for (pair<int, int> p : ranges) {
      st.make(p.first + i + 1, min(p.second + i + 1, n), a);
    }
  }
  cout << st.val(n - 1) << endl;
}

int32_t main() {

  // remove for interactive problems
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  solve();
  cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC
       << "ms\\n";

  return 0;
}


#include <bits/stdc++.h>

using ll = long long;
const ll mod = 998244353;
using namespace std;

#define int ll
struct node {
  ll val = 0;
  ll lz = 0;
} st[1 << 19];

void push(int p, int l = 0, int r = 0) {
  st[p].val %= mod;
  st[p].val += st[p].lz * (r - l + 1);
  st[p].val %= mod;
  st[p * 2].lz += st[p].lz;
  st[p * 2].lz %= mod;
  st[p * 2 + 1].lz += st[p].lz;
  st[p * 2 + 1].lz %= mod;
  st[p].lz = 0;
}
void update(int p, int l, int r, int i, int j, ll val) {
  push(p);
  if (r < i || j < l)
    return;
  if (i <= l && r <= j) {
    st[p].lz = val;
    push(p, l, r);
  } else {
    int m = (l + r) / 2;
    update(p * 2, l, m, i, j, val);
    update(p * 2 + 1, m + 1, r, i, j, val);
  }
}

int qry(int p, int l, int r, int i) {
  push(p);
  if (l == r) {
    return st[p].val;
  } else {
    int m = (l + r) / 2;
    if (i <= m) {
      return qry(p * 2, l, m, i);
    } else {
      return qry(p * 2 + 1, m + 1, r, i);
    }
  }
}

signed main() {
  int n, k;
  cin >> n >> k;
  vector<pair<int, int>> segs;
  while (k--) {
    int l, r;
    cin >> l >> r;
    segs.emplace_back(l, r);
  }
  update(1, 0, n - 1, 0, 0, 1);
  for (int i = 0; i < n - 1; i++) {
    for (auto p : segs) {
      int l, r;
      l = p.first;
      r = p.second;
      if (i + l < n) {
        update(1, 0, n - 1, i + l, min(n - 1, i + r),
               qry(1, 0, n - 1, i) % mod);
      }
    }
  }
  cout << qry(1, 0, n - 1, n - 1);
}

#include <bits/stdc++.h>

using ll = long long;
const ll mod = 998244353;
using namespace std;

#define int ll
struct node {
  ll val = 0;
  ll lz = 0;
} st[8000001];

void push(int p, int l = 0, int r = 0) {
  st[p].val %= mod;
  st[p].val += st[p].lz * (r - l + 1);
  st[p].val %= mod;
  st[p * 2].lz += st[p].lz;
  st[p * 2].lz %= mod;
  st[p * 2 + 1].lz += st[p].lz;
  st[p * 2 + 1].lz %= mod;
  st[p].lz = 0;
}
void update(int p, int l, int r, int i, int j, ll val) {
  push(p);
  if (r < i || j < l)
    return;
  if (i <= l && r <= j) {
    st[p].lz = val;
    push(p, l, r);
  } else {
    int m = (l + r) / 2;
    update(p * 2, l, m, i, j, val);
    update(p * 2 + 1, m + 1, r, i, j, val);
  }
}

int qry(int p, int l, int r, int i) {
  push(p);
  if (l == r) {
    return st[p].val;
  } else {
    int m = (l + r) / 2;
    if (i <= m) {
      return qry(p * 2, l, m, i);
    } else {
      return qry(p * 2 + 1, m + 1, r, i);
    }
  }
}

signed main() {
  int n, k;
  cin >> n >> k;
  vector<pair<int, int>> segs;
  while (k--) {
    int l, r;
    cin >> l >> r;
    segs.emplace_back(l, r);
  }
  update(1, 0, n - 1, 0, 0, 1);
  for (int i = 0; i < n - 1; i++) {
    for (auto p : segs) {
      int l, r;
      l = p.first;
      r = p.second;
      if (i + l < n) {
        update(1, 0, n - 1, i + l, min(n - 1, i + r),
               qry(1, 0, n - 1, i) % mod);
      }
    }
  }
  cout << qry(1, 0, n - 1, n - 1);
}


#include <math.h>

#include <algorithm>
#include <array>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <vector>

using namespace std;
using Graph = vector<vector<int>>;

using ll = long long;
typedef pair<ll, ll> P_ll;
typedef pair<int, int> P;

const ll INF_ll = 1e17;
const int INF = 1e8;

int main() {
  ll MOD = 998244353;

  int N, K;
  cin >> N >> K;
  vector<vector<int>> lr(K, vector<int>(2));
  vector<int> d(0);
  for (int i = 0; i < K; i++) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++) {
      d.push_back(j);
    }
  }
  sort(d.begin(), d.end());
  vector<ll> dp(N + 1, 0);
  dp[1] = 1;
  for (int i = 1; i < N + 1; i++) {
    for (int j = 0; j < d.size(); j++) {
      if (i < d[j]) {
        continue;
      }
      dp[i] += dp[i - d[j]];
      dp[i] %= MOD;
    }
    // for (int i = 1; i < N + 1; i++) {
    //   cout << dp[i] << " ";
    // }
    // cout << endl;
  }

  // for (int i = 0; i < N + 1; i++) {
  //   cout << dp[i] << endl;
  // }

  cout << dp[N] << endl;

  return 0;
}

#include <math.h>

#include <algorithm>
#include <array>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <vector>

using namespace std;
using Graph = vector<vector<int>>;

using ll = long long;
typedef pair<ll, ll> P_ll;
typedef pair<int, int> P;

const ll INF_ll = 1e17;
const int INF = 1e8;

int main() {
  ll MOD = 998244353;

  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 + 1, 0);
  vector<ll> dpsum(N + 1, 0);
  dp[1] = 1;
  dpsum[1] = 1;
  for (int i = 2; i <= N; i++) {
    for (int j = 0; j < K; j++) {
      int l_idx = i - r[j];
      int r_idx = i - l[j];
      if (r_idx < 0) {
        continue;
      }
      l_idx = max(l_idx, 1);
      dp[i] += dpsum[r_idx] - dpsum[l_idx - 1];
      if (dp[i] < 0) {
        dp[i] = (dp[i] + MOD) % MOD;
      }

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

  cout << dp[N] << endl;

  return 0;
}


#include <bits/stdc++.h>
#include <cmath>
#define pb push_back
#define ld long double
#define mp make_pair
#define vl vector<ll>
#define vd vector<double>
#define vld vector<long double>
#define ll long long int
#define pl pair<ll, ll>
#define all(a) a.begin(), a.end()
#define forr(i, n) for (ll i = 0; i < n; i++)
#define forr1(i, n) for (ll i = 1; i <= n; i++)
using namespace std;
const ld PI = 3.1415926535897923846;
const ll MOD = 1000000007;
const ll N = 998244353;
ll power(ll x, ll n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * x % MOD;
    x = x * x % MOD;
    n >>= 1;
  }
  return res;
}
ll modinverse(ll a) { return power(a, MOD - 2); }
// so, this has to be some sort of dp
// dp[i] has to be the number of ways to get to i
// fuck you, ktksan lmao
void solve() {
  ll n, k;
  cin >> n >> k;
  vl seg;
  forr(i, k) {
    ll l, r;
    cin >> l >> r;
    for (ll ii = l; ii <= r; ii++)
      seg.pb(ii);
  }
  sort(all(seg));
  vl dp(n + 1, 0);
  dp[1] = 1;
  for (ll i = 1; i <= n; i++) {
    if (dp[i] == 0)
      continue;
    forr(j, (ll)seg.size()) {
      if (seg[j] + i > n)
        break;
      dp[i + seg[j]] += dp[i];
      dp[i + seg[j]] %= N;
    }
  }
  cout << dp[n] << endl;
  return;
}
int main() {
#ifndef ONLINE_JUDGE
  // for getting input from input.txt
  freopen("input.txt", "r", stdin);
  // for writing output to output.txt
  freopen("output.txt", "w", stdout);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll test = 1;
  // cin>>test;
  while (test--) {
    solve();
  }
  cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC
       << "ms\\n";
}

#include <bits/stdc++.h>
#define pb push_back
typedef long long ll;
using namespace std;
const int mx = 5e5;
const ll mod = 998244353;
ll res[mx + 5];
int main() {
  res[1] = 1;
  int n, k;
  cin >> n >> k;
  vector<pair<int, int>> vec(k);
  for (int i = 0; i < k; ++i) {
    cin >> vec[i].first >> vec[i].second;
  }
  for (int i = 2; i <= n; ++i) {
    for (int j = 0; j < k; ++j) {
      if (i - vec[j].first < 1)
        continue;

      if (i - vec[j].second < 1)
        res[i] += res[i - vec[j].first];

      else
        res[i] += res[i - vec[j].first] - res[i - vec[j].second - 1];

      res[i] %= mod;
    }
    if (i != n)
      res[i] += res[i - 1];
  }
  cout << res[n] << endl;
}


#include <bits/stdc++.h>
#include <cassert>
#define rep(i, N) for (int i = 0; i < (N); ++i)
#define rep2(i, a, b) for (ll i = a; i <= b; ++i)
#define rep3(i, a, b) for (ll i = a; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(c) begin(c), end(c)
#define ok() puts(ok ? "Yes" : "No");
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using ii = pair<int, int>;
using vvi = vector<vi>;
using vii = vector<ii>;
using gt = greater<int>;
using minq = priority_queue<int, vector<int>, gt>;
using P = pair<ll, ll>;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
// clang++ -std=c++11 -stdlib=libc++

ll dp[200005];
int used[200006];
int main() {
  int N, K;
  cin >> N >> K;
  int mod = 998244353;
  vi s;
  rep(i, K) {
    int a, b;
    cin >> a >> b;
    rep2(j, a, b) {
      if (!used[j])
        s.pb(j);
      used[j] = true;
    }
  }
  sort(all(s));
  dp[1] = 1;
  rep2(i, 1, N) {
    bool changed = false;
    for (int num : s) {
      int ns = i + num;
      if (ns <= N) {
        (dp[ns] += dp[i]) %= mod;
        changed = true;
      } else
        break;
    }
    if (!changed)
      break;
  }
  cout << dp[N] << endl;
  return 0;
}

#include <bits/stdc++.h>
#include <cassert>
#define rep(i, N) for (int i = 0; i < (N); ++i)
#define rep2(i, a, b) for (ll i = a; i <= b; ++i)
#define rep3(i, a, b) for (ll i = a; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(c) begin(c), end(c)
#define ok() puts(ok ? "Yes" : "No");
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using ii = pair<int, int>;
using vvi = vector<vi>;
using vii = vector<ii>;
using gt = greater<int>;
using minq = priority_queue<int, vector<int>, gt>;
using P = pair<ll, ll>;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
// clang++ -std=c++11 -stdlib=libc++

ll dp[200005];
ll dpsum[200005];
int mod = 998244353;
int main() {
  int N, K;
  cin >> N >> K;
  vi L(N), R(N);
  rep(i, K) cin >> L[i] >> R[i];
  dp[1] = 1;
  dpsum[1] = dp[1];
  rep2(i, 2, N) {
    rep(j, K) {
      int l = i - R[j];
      int r = i - L[j];
      if (r < 0)
        continue;
      chmax(l, 1);
      (dp[i] += dpsum[r] - dpsum[l - 1]) %= mod;
      if (dp[i] < 0)
        dp[i] += mod;
    }
    dpsum[i] = (dpsum[i - 1] + dp[i]) % mod;
    if (dpsum[i] < 0)
      dpsum[i] += mod;
  }
  cout << dp[N] << endl;
  return 0;
}


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 998244353LL

#define rep(i, n) for (ll(i) = 0LL; (i) < (ll)(n); (i)++)
#define rep2(i, s, e) for (ll(i) = (ll)(s); (i) < (ll)(e); (i)++)
#define repi(i, n) for (ll(i) = 0LL; (i) <= (ll)(n); (i)++)
#define repi2(i, s, e) for (ll(i) = (ll)(s); (i) <= (ll)(e); (i)++)
#define per(i, n) for (ll(i) = (ll)(n)-1LL; (i) >= 0LL; (i)--)
#define per2(i, s, e) for (ll(i) = (ll)(s)-1LL; (i) >= (ll)(e); (i)--)
#define peri(i, n) for (ll(i) = (ll)(n); (i) >= 0LL; (i)--)
#define peri2(i, s, e) for (ll(i) = (ll)(s); (i) >= (ll)(e); (i)--)
#define iter(i, it) for (auto &(i) : (it))

template <typename T, typename U>
ostream &operator<<(ostream &s, const pair<T, U> m) {
  cout << "(" << m.first << ", " << m.second << ")";
  return s;
}
template <typename T, typename U>
ostream &operator<<(ostream &s, const map<T, U> m) {
  ll c = 0;
  cout << "{ ";
  iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
  cout << "}";
  return s;
}
template <typename T> ostream &operator<<(ostream &s, const vector<T> &v) {
  cout << "{ ";
  rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
  cout << "}";
  return s;
}
template <typename T> ostream &operator<<(ostream &s, const list<T> &v) {
  ll c = 0;
  cout << "{ ";
  iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
  cout << "}";
  return s;
}

int main(void) {
  ll N, K;
  cin >> N >> K;
  vector<ll> S;
  rep(i, K) {
    ll l, r;
    cin >> l >> r;
    repi2(j, l, r) S.push_back(j);
  }
  vector<ll> dp(N);
  dp.front() = 1;
  rep(i, N) {
    if (dp[i] == 0)
      continue;
    iter(j, S) {
      ll temp = (i + j) % MOD;
      if (temp < dp.size())
        (dp[temp] += dp[i]) %= MOD;
    }
  }
  cout << dp.back() << endl;
  return 0;
}

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 998244353LL

#define rep(i, n) for (ll(i) = 0LL; (i) < (ll)(n); (i)++)
#define rep2(i, s, e) for (ll(i) = (ll)(s); (i) < (ll)(e); (i)++)
#define repi(i, n) for (ll(i) = 0LL; (i) <= (ll)(n); (i)++)
#define repi2(i, s, e) for (ll(i) = (ll)(s); (i) <= (ll)(e); (i)++)
#define per(i, n) for (ll(i) = (ll)(n)-1LL; (i) >= 0LL; (i)--)
#define per2(i, s, e) for (ll(i) = (ll)(s)-1LL; (i) >= (ll)(e); (i)--)
#define peri(i, n) for (ll(i) = (ll)(n); (i) >= 0LL; (i)--)
#define peri2(i, s, e) for (ll(i) = (ll)(s); (i) >= (ll)(e); (i)--)
#define iter(i, it) for (auto &(i) : (it))

template <typename T, typename U>
ostream &operator<<(ostream &s, const pair<T, U> m) {
  cout << "(" << m.first << ", " << m.second << ")";
  return s;
}
template <typename T, typename U>
ostream &operator<<(ostream &s, const map<T, U> m) {
  ll c = 0;
  cout << "{ ";
  iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
  cout << "}";
  return s;
}
template <typename T> ostream &operator<<(ostream &s, const vector<T> &v) {
  cout << "{ ";
  rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
  cout << "}";
  return s;
}
template <typename T> ostream &operator<<(ostream &s, const list<T> &v) {
  ll c = 0;
  cout << "{ ";
  iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
  cout << "}";
  return s;
}

int main(void) {
  ll N, K;
  cin >> N >> K;
  vector<pair<ll, ll>> S;
  rep(i, K) {
    ll l, r;
    cin >> l >> r;
    S.emplace_back(l, r);
  }
  vector<ll> dp(N);
  dp.front() = 1;
  dp[1] = -1;
  rep(i, N - 1) {
    if (dp[i] == 0)
      continue;
    iter(j, S) {
      ll temp;
      temp = (i + j.first) % MOD;
      if (temp < dp.size()) {
        (dp[temp] += dp[i]) %= MOD;
      }
      temp = (i + j.second + 1) % MOD;
      if (temp < dp.size()) {
        (dp[temp] -= dp[i]) %= MOD;
        if (dp[temp] < 0)
          (dp[temp] += MOD) %= MOD;
      }
    }
    (dp[i + 1] += dp[i]) %= MOD;
  }
  cout << dp.back() << endl;
  return 0;
}


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

#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (ll i = m; i < (n); i++)

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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> V;
  rep(i, K) {
    int L, R;
    cin >> L >> R;
    for (int i = L; i <= R; i++) {
      V.push_back(i);
    }
  }

  vector<long long> dp(200010, 0);
  dp[1] = 1;

  for (int i = 1; i <= N; i++) {
    for (auto v : V) {
      if (i + v > N)
        continue;
      dp[i + v] += dp[i];
      dp[i + v] %= 998244353;
    }
  }

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

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

#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (ll i = m; i < (n); i++)

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

int main() {
  ll N, K;
  cin >> N >> K;
  vector<pair<ll, ll>> V;
  for (ll i = 0; i < K; i++) {
    ll L, R;
    cin >> L >> R;
    V.push_back(make_pair(L, R));
  }

  sort(V.begin(), V.end());
  vector<long long> dp(200010, 0);
  dp[1] = 1;
  dp[1 + V[0].first] = 1;

  for (ll i = V[0].first + 2; i <= 200010; i++) {
    long long dif = 0;
    for (auto v : V) {
      dif += (dp[max(0LL, i - v.first)] - dp[max(0LL, i - v.second - 1)]);
      dif += 998244353;
      dif %= 998244353;
    }
    dp[i] = dp[i - 1] + dif;
    dp[i] %= 998244353;
  }

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


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int INF = 0x3f3f3f3f;
const LL mod = 998244353;
const int N = 200005;

int a[N], b[N];
LL f[N], c[20];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
  }
  f[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < m; j++) {
      c[j] += (i - a[j] >= 1 ? f[i - a[j]] : 0) -
              (f[i - b[j] - 1] >= 1 ? f[i - b[j] - 1] : 0);

      f[i] = (f[i] + c[j]) % mod;
    }
  }
  cout << (f[n] + mod) % mod << endl;
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int INF = 0x3f3f3f3f;
const LL mod = 998244353;
const int N = 200005;

int a[N], b[N];
LL f[N], c[20];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
  }
  f[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < m; j++) {
      c[j] += (i - a[j] >= 1 ? f[i - a[j]] : 0) -
              (i - b[j] - 1 >= 1 ? f[i - b[j] - 1] : 0);

      f[i] = (f[i] + c[j]) % mod;
    }
  }
  cout << (f[n] + mod) % mod << endl;
  return 0;
}