// Problem : D - Leaping Tak
// Contest : AtCoder - AtCoder Beginner Contest 179
// URL : https://atcoder.jp/contests/abc179/tasks/abc179_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

// Macros

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long
#define db long double
#define pb push_back
#define eb emplace_back
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int, int>
#define mii map<pii, int>
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define sz(x) (int)x.size()
#define mod 998244353
#define EPS 1e-9
#define inf 1e10
#define PI acos(-1.0)
#define int long long
#define N 100005

// Solution

int n, k;
vii p;

class SegTree {
  int tl, tr, sum;
  SegTree *left, *right;

public:
  SegTree(int l, int r) {
    sum = 0;
    tl = l;
    tr = r;
    left = nullptr;
    right = nullptr;
  }

  void makeChildren() {
    int tm = (tl + tr) / 2;
    left = new SegTree(tl, tm);
    right = new SegTree(tm + 1, tr);
  }

  void update(int pos, int val) {
    sum += val;
    if (tl == tr)
      return;
    if (left == nullptr)
      makeChildren();
    if (pos <= left->tr)
      left->update(pos, val);
    else
      right->update(pos, val);
  }

  int get(int l, int r) {
    if (l > tr || r < tl)
      return 0;
    if (tl >= l && tr <= r)
      return sum;
    if (left == nullptr)
      return 0;
    return left->get(l, r) + right->get(l, r);
  }
};

void solve() {
  cin >> n >> k;
  p.resize(n);
  for (auto &[a, b] : p) {
    cin >> a >> b;
  }
  SegTree *st = new SegTree(1, n);
  vector<int> dp(n + 1);
  dp[1] = 1;
  st->update(1, 1);
  for (int i = 2; i <= n; i++) {
    for (auto [a, b] : p) {
      int l = max(1ll, i - b);
      int r = max(0ll, i - a);
      dp[i] += st->get(l, r);
      dp[i] %= mod;
    }
    st->update(i, dp[i]);
  }
  cout << dp[n];
}

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

  int tests;
  tests = 1;
  // cin>>tests;

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

  return 0;
}

// Problem : D - Leaping Tak
// Contest : AtCoder - AtCoder Beginner Contest 179
// URL : https://atcoder.jp/contests/abc179/tasks/abc179_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

// Macros

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long
#define db long double
#define pb push_back
#define eb emplace_back
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int, int>
#define mii map<pii, int>
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define sz(x) (int)x.size()
#define mod 998244353
#define EPS 1e-9
#define inf 1e10
#define PI acos(-1.0)
#define int long long
#define N 100005

// Solution

int n, k;
vii p;

class SegTree {
  int tl, tr, sum;
  SegTree *left, *right;

public:
  SegTree(int l, int r) {
    sum = 0;
    tl = l;
    tr = r;
    left = nullptr;
    right = nullptr;
  }

  void makeChildren() {
    int tm = (tl + tr) / 2;
    left = new SegTree(tl, tm);
    right = new SegTree(tm + 1, tr);
  }

  void update(int pos, int val) {
    sum += val;
    if (tl == tr)
      return;
    if (left == nullptr)
      makeChildren();
    if (pos <= left->tr)
      left->update(pos, val);
    else
      right->update(pos, val);
  }

  int get(int l, int r) {
    if (l > tr || r < tl)
      return 0;
    if (tl >= l && tr <= r)
      return sum;
    if (left == nullptr)
      return 0;
    return left->get(l, r) + right->get(l, r);
  }
};

void solve() {
  cin >> n >> k;
  p.resize(k);
  for (auto &[a, b] : p) {
    cin >> a >> b;
  }
  SegTree *st = new SegTree(1, n);
  vector<int> dp(n + 1);
  dp[1] = 1;
  st->update(1, 1);
  for (int i = 2; i <= n; i++) {
    for (auto [a, b] : p) {
      int l = max(1ll, i - b);
      int r = max(0ll, i - a);
      dp[i] += st->get(l, r);
      dp[i] %= mod;
    }
    st->update(i, dp[i]);
  }
  cout << dp[n];
}

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

  int tests;
  tests = 1;
  // cin>>tests;

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

  return 0;
}


// D - Leaping Tak
#include <bits/stdc++.h>

using namespace std;

#define MOD 998244353

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> s;
  for (int i = 0; i < k; i++) {
    int l, r;
    cin >> l >> r;
    for (int x = l; x <= r; x++)
      s.push_back(x);
  }
  sort(s.begin(), s.end());

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

  cout << dp[n] << endl;

  return 0;
}

// D - Leaping Tak
#include <bits/stdc++.h>

using namespace std;

#define MOD 998244353

void fen_update(vector<long long> &tree, int i, long long delta) {
  for (; i < tree.size(); i |= i + 1)
    tree[i] = (tree[i] + delta) % MOD;
}

long long fen_get(const vector<long long> &tree, int i) {
  long long sum = 0;
  for (; i > 0; i &= i - 1)
    sum = (sum + tree[i - 1]) % MOD;
  return sum;
}

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<pair<int, int>> s(k);
  for (int i = 0; i < k; i++)
    cin >> s[i].first >> s[i].second;
  sort(s.begin(), s.end());
  vector<long long> t(n);
  fen_update(t, 0, 1);
  for (int i = 1; i < n; i++)
    for (auto x : s) {
      if (i - x.first < 0)
        break;
      int r = max(0, i - x.first), l = max(0, i - x.second);
      long long d = (fen_get(t, r + 1) - fen_get(t, l) + MOD) % MOD;
      fen_update(t, i, d);
    }

  cout << (fen_get(t, n) - fen_get(t, n - 1) + MOD) % MOD << endl;

  return 0;
}


/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;
typedef long long ll;
typedef long double ld;

int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int> &f, const pair<int, int> &s) {
  return f.second > s.second;
}

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

ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

ll conbinationMemo[100][100];

void cmemoInit() {
  rep(i, 100) {
    rep(j, 100) { conbinationMemo[i][j] = -1; }
  }
}

ll nCr(ll n, ll r) {
  if (conbinationMemo[n][r] != -1)
    return conbinationMemo[n][r];
  if (r == 0 || r == n) {
    return 1;
  } else if (r == 1) {
    return n;
  }
  return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1));
}

ll nPr(ll n, ll r) {
  r = n - r;
  ll ret = 1;
  for (ll i = n; i >= r + 1; i--)
    ret *= i;
  return ret;
}
//-----------------------ここから-----------
ll mod = 998244353;
int main(void) {
  ll n, k;
  cin >> n >> k;
  vector<pair<ll, ll>> vec;
  rep(i, k) {
    ll l, r;
    cin >> l >> r;
    vec.push_back({l, r});
  }
  sort(all(vec));
  ll dp[200100];
  dp[0] = 1;
  dp[1] = -1;
  ll now = 0;
  rep(i, n) {
    now += dp[i];
    while (now < 0)
      now += mod;
    now %= mod;
    rep(j, vec.size()) {
      if (i + vec[j].first < n) {
        dp[i + vec[j].first] += now;
        dp[i + vec[j].first] %= mod;
      }
      if (i + vec[j].second + 1 < n) {
        dp[i + vec[j].second + 1] -= now;
        while (dp[i + vec[j].second + 1] < 0)
          dp[i + vec[j].second + 1] += mod;
        dp[i + vec[j].second + 1] %= mod;
      }
    }
  }
  while (now < 0)
    now += mod;
  cout << now % mod << endl;
}

/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;
typedef long long ll;
typedef long double ld;

int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int> &f, const pair<int, int> &s) {
  return f.second > s.second;
}

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

ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

ll conbinationMemo[100][100];

void cmemoInit() {
  rep(i, 100) {
    rep(j, 100) { conbinationMemo[i][j] = -1; }
  }
}

ll nCr(ll n, ll r) {
  if (conbinationMemo[n][r] != -1)
    return conbinationMemo[n][r];
  if (r == 0 || r == n) {
    return 1;
  } else if (r == 1) {
    return n;
  }
  return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1));
}

ll nPr(ll n, ll r) {
  r = n - r;
  ll ret = 1;
  for (ll i = n; i >= r + 1; i--)
    ret *= i;
  return ret;
}
//-----------------------ここから-----------
ll mod = 998244353;
int main(void) {
  ll n, k;
  cin >> n >> k;
  vector<pair<ll, ll>> vec;
  rep(i, k) {
    ll l, r;
    cin >> l >> r;
    vec.push_back({l, r});
  }
  sort(all(vec));
  ll dp[200100] = {0};
  dp[0] = 1;
  dp[1] = -1;
  ll now = 0;
  rep(i, n) {
    now += dp[i];
    while (now < 0)
      now += mod;
    now %= mod;
    rep(j, vec.size()) {
      if (i + vec[j].first < n) {
        dp[i + vec[j].first] += now;
        dp[i + vec[j].first] %= mod;
      }
      if (i + vec[j].second + 1 < n) {
        dp[i + vec[j].second + 1] -= now;
        while (dp[i + vec[j].second + 1] < 0)
          dp[i + vec[j].second + 1] += mod;
        dp[i + vec[j].second + 1] %= mod;
      }
    }
  }
  while (now < 0)
    now += mod;
  cout << now % mod << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define IOS                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)
#define pb push_back
#define ff first
#define ss second
#define vll vector<ll>
#define pii pair<ll, ll>
#define sz(v) (v).size()
#define srt(v) sort(v.begin(), v.end())
#define ull unsigned long long
#define tell(a) cout << a << " "
#define el cout << endl
#define rev(v) reverse(v.begin(), v.end())
#define rep(i, a, n) for (int i = a; i < n; i++)
#define ld long double
#define mem(a, b) memset(a, b, sizeof(a))
#define M 1000000
#define md 998244353

ll power(ll x, ll y, ll p) {
  ll res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
/*inline ll add(ll a,ll b){return (a+b)%md;}
inline ll mul(ll a,ll b){return (a*b)%md;}
ll f[M],iv[M];
ll C(ll n,ll r){return mul(f[n],mul(iv[r],iv[n-r]));}
void prep_fac(){
    f[0]=1;
    rep(i,1,M)f[i]=mul(i,f[i-1]);
    iv[M-1]=power(f[M-1],md-2,md);
    for(ll i=M-2;i>=0;--i)iv[i]=mul(i+1,iv[i+1]);
}*/

int main() {
  IOS;
  int n, k;
  cin >> n >> k;
  set<int> s;
  for (int i = 0; i < k; i++) {
    int x, y;
    cin >> x >> y;
    for (int j = x; j <= y; j++)
      s.insert(j);
  }
  vll v;
  for (auto it = s.begin(); it != s.end(); it++) {
    v.pb(*it);
  }
  ll dp[n + 1];
  mem(dp, 0);
  dp[1] = 1;
  for (int i = 2; i <= n; i++) {
    int pos = lower_bound(v.begin(), v.end(), i) - v.begin();
    for (int j = 0; j < pos; j++) {
      if (i - v[j] >= 1) {
        dp[i] += dp[i - v[j]];
        dp[i] %= md;
      }
    }
  }
  cout << dp[n] % md;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define IOS                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)
#define pb push_back
#define ff first
#define ss second
#define vll vector<ll>
#define pii pair<ll, ll>
#define sz(v) (v).size()
#define srt(v) sort(v.begin(), v.end())
#define ull unsigned long long
#define tell(a) cout << a << " "
#define el cout << endl
#define rev(v) reverse(v.begin(), v.end())
#define rep(i, a, n) for (int i = a; i < n; i++)
#define ld long double
#define mem(a, b) memset(a, b, sizeof(a))
#define M 1000000
#define md 998244353

ll power(ll x, ll y, ll p) {
  ll res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
/*inline ll add(ll a,ll b){return (a+b)%md;}
inline ll mul(ll a,ll b){return (a*b)%md;}
ll f[M],iv[M];
ll C(ll n,ll r){return mul(f[n],mul(iv[r],iv[n-r]));}
void prep_fac(){
    f[0]=1;
    rep(i,1,M)f[i]=mul(i,f[i-1]);
    iv[M-1]=power(f[M-1],md-2,md);
    for(ll i=M-2;i>=0;--i)iv[i]=mul(i+1,iv[i+1]);
}*/

int main() {
  IOS;
  int n, k;
  cin >> n >> k;
  vector<pii> v;
  for (int i = 0; i < k; i++) {
    int x, y;
    cin >> x >> y;
    v.pb({x, y});
  }

  ll dp[n + 1], pre[n + 2];
  mem(dp, 0);
  dp[1] = 1;
  pre[2] = 1;
  pre[1] = 0;
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < k; j++) {
      int u = i - v[j].ff;
      int l = i - v[j].ss;
      if (u < 1)
        continue;
      dp[i] = (dp[i] + pre[u + 1] - (l >= 1 ? pre[l] : 0) + md) % md;
    }
    pre[i + 1] = (pre[i] + dp[i]) % md;
  }
  cout << dp[n] % md;
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define mod 998244353
#define int long long int
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }

int32_t main() {

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int t = 1;
  // cin>>t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    int a[k][2];
    for (int i = 0; i < k; i++)
      cin >> a[i][0] >> a[i][1];
    vector<int> dp(n + 1, 0);
    dp[1] = 1;
    for (int i = 1; i < n; i++) {
      for (int j = 0; j < k; j++) {
        for (int p = a[j][0]; p <= a[j][1]; p++) {
          // cout<<i<<" "<<p<<endl;
          if (i + p <= n)
            dp[i + p] = (dp[i + p] % mod + dp[i] % mod) % mod;
        }
      }
    }
    cout << dp[n] << endl;
  }
}

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define mod 998244353
#define int long long int
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }

int32_t main() {

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int t = 1;
  // cin>>t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    int a[k][2];
    for (int i = 0; i < k; i++)
      cin >> a[i][0] >> a[i][1];
    vector<int> dp(n + 1, 0);
    vector<int> prev(n + 1, 0);
    dp[1] = 1;
    prev[1] = 1;
    for (int i = 2; i <= n; i++) {
      for (int j = 0; j < k; j++) {
        int l = i - a[j][0];
        int r = i - a[j][1] - 1;
        if (l <= 0) {
          continue;
        }
        r = max(r, 0LL);
        // cout<<i<<" "<<l<<" "<<r<<" "<<prev[l]-prev[r]<<endl;
        dp[i] = (dp[i] % mod + (prev[l] - prev[r]) % mod + mod) % mod;
        // cout<<dp[i]<<endl;
      }
      prev[i] = (dp[i] % mod + prev[i - 1] % mod + mod) % mod;
      // cout<<prev[i]<<" ";
    }
    cout << dp[n] % mod << endl;
  }
}
// 1 1 1 2 4
// 1 2 3 5 9


#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, k, n) for (int i = k; i < (int)(n); i++)
#define repd(i, n) for (int i = n - 1; i >= 0; i--)
#define rrepd(i, k, n) for (int i = n - 1; i >= (int)(k); i--)
#define all(x) (x).begin(), (x).end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define F first      // pairの一つ目の要素
#define S second     // pairの二つ目の要素
#define PB push_back // 挿入
#define MP make_pair // pairのコンストラクタ
// V,Pは大文字i,l,bは小文字
using ll = long long;
using Vi = vector<int>;
using VVi = vector<Vi>;
using Vl = vector<ll>;
using VVl = vector<Vl>;
using Vb = vector<bool>;
using VVb = vector<Vb>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;

const ll inf = 1000000000000; // 10の12乗
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;
  }
};

int main() {
  ll n, k;
  cin >> n >> k;
  vector<mint> v(n + 100001, 0), vv(n + 100001, 0);
  v[0] = 1;
  Vi vl(k), vr(k);
  rep(i, k) cin >> vl[i] >> vr[i];
  rep(i, n) {
    if (i != 0)
      v[i] = v[i - 1].x + vv[i].x;
    rep(j, k) {
      int x = vl[j];
      int y = vr[j] + 1;
      vv[i + x] += v[i];
      vv[i + y] -= v[i];
    }
  }

  cout << vv[n - 1].x << endl;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, k, n) for (int i = k; i < (int)(n); i++)
#define repd(i, n) for (int i = n - 1; i >= 0; i--)
#define rrepd(i, k, n) for (int i = n - 1; i >= (int)(k); i--)
#define all(x) (x).begin(), (x).end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define F first      // pairの一つ目の要素
#define S second     // pairの二つ目の要素
#define PB push_back // 挿入
#define MP make_pair // pairのコンストラクタ
// V,Pは大文字i,l,bは小文字
using ll = long long;
using Vi = vector<int>;
using VVi = vector<Vi>;
using Vl = vector<ll>;
using VVl = vector<Vl>;
using Vb = vector<bool>;
using VVb = vector<Vb>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;

const ll inf = 1000000000000; // 10の12乗
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;
  }
};

int main() {
  ll n, k;
  cin >> n >> k;
  vector<mint> v(n + 1000002, 0), vv(n + 1000002, 0);
  v[0] = 1;
  Vi vl(k), vr(k);
  rep(i, k) cin >> vl[i] >> vr[i];
  rep(i, n) {
    if (i != 0)
      v[i] = v[i - 1].x + vv[i].x;
    rep(j, k) {
      int x = vl[j];
      int y = vr[j] + 1;
      vv[i + x] += v[i];
      vv[i + y] -= v[i];
    }
  }

  cout << vv[n - 1].x << endl;
}


#include <iostream>
#include <map>
using namespace std;
const int mod = 998244353;
const int max_size = 2e5 + 11;
int n, k, a, b;
map<int, int> m;
long long dp[max_size] = {};

int main() {
  scanf("%d%d", &n, &k);
  while (k--) {
    scanf("%d%d", &a, &b);
    for (int i = a; i <= b; ++i)
      m[i]++;
  }
  dp[1] = 1;
  for (int i = 1; i <= n; ++i) {
    for (auto &it : m) {
      if (i + it.first > n)
        break;
      dp[i + it.first] += dp[i];
      dp[i + it.first] %= mod;
    }
  }
  printf("%lld", dp[n] % mod);
  return 0;
}

#include <iostream>
#include <utility>
#include <vector>
using namespace std;
const int mod = 998244353;
const int max_size = 2e5 + 11;
int n, k, a, b;
long long dp[max_size] = {};
vector<pair<int, int>> arr;

int main() {
  scanf("%d%d", &n, &k);
  while (k--) {
    scanf("%d%d", &a, &b);
    arr.emplace_back(a, b);
  }
  dp[1] = 1, dp[2] = -1;
  for (int i = 1; i <= n; ++i) {
    if (i > 1) {
      dp[i] += dp[i - 1];
      dp[i] %= mod;
    }
    for (auto &it : arr) {
      if (i + it.first <= n) {
        dp[i + it.first] += dp[i];
        dp[i + it.first] %= mod;
      }
      if (i + it.second + 1 <= n) {
        dp[i + it.second + 1] -= (dp[i] - mod);
        dp[i + it.second + 1] %= mod;
      }
    }
  }
  printf("%lld", dp[n] % mod);
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

// #define int 		long long
#define endl "\\n"
#define mod 998244353
#define inf 1e18
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)

int32_t main() {

  IOS;

  int n, k, x, y;
  cin >> n >> k;

  vector<bool> jumpT(n + 1);

  for (int i = 0; i < k; i++) {
    cin >> x >> y;

    for (int i = x; i <= y; i++)
      jumpT[i] = 1;
  }

  vector<int> jump;

  for (int i = 1; i <= n; i++) {
    if (jumpT[i])
      jump.push_back(i);
  }

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

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

    for (int dx : jump) {

      x = i + dx;
      if (x > n)
        break;

      dp[x] = (dp[x] + dp[i]) % mod;
    }
  }

  cout << dp[n];

  return 0;
}

#include <bits/stdc++.h>

using namespace std;

// #define int 		long long
#define endl "\\n"
#define mod 998244353
#define inf 1e18
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)

int32_t main() {

  IOS;

  int n, k, x, y;
  cin >> n >> k;

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

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

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

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

    for (int j = 0; j < k; j++) {
      if (i <= s[j].first)
        continue;

      int left = s[j].first;
      int right = min(s[j].second, i - 1);

      int val = (dp[i - left] - dp[i - right - 1] + mod) % mod;

      dp[i] = (dp[i] + val) % mod;
    }

    if (i != n)
      (dp[i] += dp[i - 1]) %= mod;
  }

  cout << dp[n];

  return 0;
}


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

#define fi first
#define se second
#define pb push_back

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;

const int N = 2e5;
const int MOD = 998244353;
int n, k;
int dp[N + 2];
vector<int> adj;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  clock_t ck;
  ck = clock();
  cin >> n >> k;
  for (int i = 1; i <= k; i++) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++) {
      adj.pb(j);
    }
  }
  sort(adj.begin(), adj.end());
  dp[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j : adj) {
      if (j > i)
        break;
      dp[i] += dp[i - j];
      dp[i] %= MOD;
    }
  }
  cout << dp[n] << '\\n';
  ck = clock() - ck;
  cerr << "It took " << 1.0 * ck / CLOCKS_PER_SEC << " sec\\n";
  return 0;
}

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

#define fi first
#define se second
#define pb push_back

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;

const int N = 2e5;
const int MOD = 998244353;
int n, k;
int l[N + 2], r[N + 2];
ll dp[N + 2], pref[N + 2];

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  clock_t ck;
  ck = clock();
  cin >> n >> k;
  for (int i = 1; i <= k; i++) {
    cin >> l[i] >> r[i];
  }
  dp[1] = 1;
  pref[1] = 1;
  for (int i = 2; i <= n; i++) {
    // cout << i << " :\\n";
    for (int j = 1; j <= k; j++) {
      if (i - l[j] > 0)
        dp[i] += pref[i - l[j]];
      if (i - r[j] - 1 > 0)
        dp[i] -= pref[i - r[j] - 1];
      // cout << max(0,i-l[j]) << ' ' << max(0,i-r[j]-1) << '\\n';
      dp[i] %= MOD;
      dp[i] += MOD;
      dp[i] %= MOD;
    }
    pref[i] = pref[i - 1] + dp[i];
    pref[i] %= MOD;
  }
  cout << dp[n] << '\\n';
  ck = clock() - ck;
  cerr << "It took " << 1.0 * ck / CLOCKS_PER_SEC << " sec\\n";
  return 0;
}


#include <bits/stdc++.h>
#define DEBUG if (0)
#define lli long long int
#define ldouble long double
using namespace std;

const int maxN = 2e5, maxK = 10;
int n, k;
pair<int, int> lr[maxK];

vector<int> s;
const lli mod = 998244353;
lli memo[maxN];
lli solve(int i = 1) {
  if (i >= n)
    return i == n;
  if (memo[i] != -1)
    return memo[i];

  lli ans = 0;
  int pos = lower_bound(s.begin(), s.end(), n - i) - s.begin();
  // printf("\\t%d %d\\n", n - i, pos);
  if (pos == s.size())
    pos--;
  for (int j = pos; j >= 0; j--)
    ans = (ans + solve(i + s[j])) % mod;

  return memo[i] = ans;
}

int main() {
  while (scanf("%d %d", &n, &k) != EOF) {
    s.clear();
    for (int i = 0; i < k; i++) {
      scanf("%d %d", &lr[i].first, &lr[i].second);
      for (int j = 0, end = lr[i].second - lr[i].first + 1; j < end; j++)
        s.push_back(lr[i].first + j);
    }
    sort(s.begin(), s.end(), less<int>());

    memset(memo, -1, sizeof(memo));
    lli ans = solve();
    printf("%lld\\n", ans);
  }
  return 0;
}

#include <bits/stdc++.h>
#define DEBUG if (0)
#define lli long long int
#define ldouble long double
using namespace std;

const int maxN = 2e5, maxK = 10;
int n, k;
pair<int, int> lr[maxK];

vector<int> s[maxK];
const lli mod = 998244353;
lli memo[maxN];

int lowerBound(int j, int target) {
  int lo = 0, hi = s[j].size() - 1;
  while (lo < hi) {
    int mid = (lo + hi + 1) >> 1;
    if (s[j][mid] <= target)
      lo = mid;
    else
      hi = mid - 1;
  }
  return s[j][lo] <= target ? lo : -1;
}

struct Data {
  lli value;
  Data operator+(const Data &other) {
    return Data{(value + other.value) % mod};
  }
};
const Data nil = Data{0LL};

// DON'T FORGET TO DEFINE THE NIL!!!
template <class T> struct Segtree {
  int size;
  T nil;
  vector<T> data;
  vector<T> st;
  Segtree() {}
  Segtree(int size, T nil) : size(size), nil(nil) {
    data.resize(size);
    st.resize(4 * size);
  }
  Segtree(vector<T> &data, T nil) : size(data.size()), data(data), nil(nil) {
    st.resize(4 * size);
    build();
  }
  void build() { build(1, 0, size - 1); }
  T query(int qlo, int qhi) { return query(qlo, qhi, 1, 0, size - 1); }
  void update(int pos, T value) { update(pos, value, 1, 0, size - 1); }
  void build(int i, int lo, int hi) {
    if (lo == hi) {
      st[i] = data[lo];
      return;
    }
    int mid = (lo + hi) >> 1;
    build(2 * i, lo, mid), build(2 * i + 1, mid + 1, hi);
    st[i] = st[2 * i] + st[2 * i + 1];
  }
  T query(int qlo, int qhi, int i, int lo, int hi) {
    if (hi < qlo || lo > qhi)
      return nil;
    if (lo >= qlo && hi <= qhi)
      return st[i];
    int mid = (lo + hi) >> 1;
    return query(qlo, qhi, 2 * i, lo, mid) +
           query(qlo, qhi, 2 * i + 1, mid + 1, hi);
  }
  void update(int pos, T &value, int i, int lo, int hi) {
    if (lo == hi) {
      st[i] = (st[i] + value);
      return;
    }
    int mid = (lo + hi) >> 1;
    if (pos <= mid)
      update(pos, value, 2 * i, lo, mid);
    else
      update(pos, value, 2 * i + 1, mid + 1, hi);
    st[i] = st[2 * i] + st[2 * i + 1];
  }
};
Segtree<Data> segtree;

int main() {
  while (scanf("%d %d", &n, &k) != EOF) {
    for (int i = 0; i < k; i++) {
      s[i].clear();
      scanf("%d %d", &lr[i].first, &lr[i].second);
      for (int j = 0, end = lr[i].second - lr[i].first + 1; j < end; j++)
        s[i].push_back(lr[i].first + j);
    }
    segtree = Segtree<Data>(n + 1, nil);
    for (int i = 0; i <= n; i++)
      segtree.data[i].value = 0;
    segtree.build();

    // memset(memo, 0, sizeof(memo));
    // memo[0] = 1;
    segtree.update(0, Data{1LL});
    for (int i = 1; i <= n; i++)
      for (int j = 0; j < k; j++) {
        int last = lowerBound(j, i);
        if (last >= 0) {
          Data got = segtree.query(i - s[j][last], i - s[j][0]);
          // for (int jj = 0; jj <= last; jj++)
          //   segtree.update(i, segtree.query(i - s[j][jj], i - s[j][jj]));
          // memo[i] = (memo[i] + memo[i - s[j]]) % mod;
          segtree.update(i, got);
        }
      }

    lli ans = segtree.query(n - 1, n - 1).value;
    printf("%lld\\n", ans);
  }
  return 0;
}


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

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

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint &operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};
int main() {
  int N, K;
  cin >> N >> K;
  vector<int> L(K);
  vector<int> R(K);
  rep(i, K) cin >> L[i] >> R[i];

  vector<mint> dp(N + 100);
  dp[1] = 1;
  for (int i = 1; i < N + 1; i++) {
    dp[i] += dp[i - 1];
    rep(j, K) {
      int l = L[j] + i;
      int r = min(R[j] + i, N + 10);
      dp[l] += dp[i];
      dp[r + 1] -= dp[i];
    }
  }
  cout << (dp[N] - dp[N - 1]).x << endl;
  return 0;
}

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

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

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint &operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};
int main() {
  int N, K;
  cin >> N >> K;
  vector<int> L(K);
  vector<int> R(K);
  rep(i, K) cin >> L[i] >> R[i];

  vector<mint> dp(N + 100);
  dp[1] = 1;
  for (int i = 1; i < N + 1; i++) {
    dp[i] += dp[i - 1];
    rep(j, K) {
      int l = min(L[j] + i, N + 10);
      int r = min(R[j] + i, N + 10);
      dp[l] += dp[i];
      dp[r + 1] -= dp[i];
    }
  }
  cout << (dp[N] - dp[N - 1]).x << endl;
  return 0;
}


#include <bits/stdc++.h>
#define fastio                                                                 \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define endl "\\n"
#define int long long int
using namespace std;
int mod = 998244353;

int n;
int dp[100001];
int find(vector<int> v, int curr) {
  if (curr == n)
    return 1;
  if (curr > n)
    return 0;
  if (dp[curr] != -1)
    return dp[curr];
  int ans = 0;
  for (int j = 0; j < v.size(); j++) {
    if (curr + v[j] <= n) {
      ans = (ans + find(v, curr + v[j])) % mod;
    }
  }
  return dp[curr] = ans % mod;
}

int32_t main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  fastio;

  int k, a, b;
  cin >> n >> k;
  memset(dp, -1, sizeof dp);
  set<int> s;
  for (int i = 0; i < k; i++) {
    cin >> a >> b;
    s.insert(a), s.insert(b);
  }
  vector<int> v;
  for (auto it = s.begin(); it != s.end(); it++) {
    a = (int)*it;
    v.push_back(a);
  }
  cout << find(v, 1);
  return 0;
}

#include <bits/stdc++.h>
#define fastio                                                                 \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define endl "\\n"
#define int long long int
using namespace std;
int mod = 998244353;

int n;
// int dp[100000001];
// int find(vector<int> v, int curr) {
// 	if (curr == n)
// 		return 1;
// 	if (curr > n)
// 		return 0;
// 	if (dp[curr] != -1)
// 		return dp[curr];
// 	int ans = 0;
// 	for (int j = 0; j < v.size(); j++) {
// 		if (curr + v[j] <= n) {
// 			ans = (ans + find(v, curr + v[j])) % mod;
// 		}
// 	}
// 	return dp[curr] = ans % mod;
// }

int32_t main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  fastio;

  int k, a, b;
  cin >> n >> k;
  int l[k], r[k];
  for (int i = 0; i < k; i++) {
    cin >> l[i] >> r[i];
    ++r[i];
  }
  int dp[n];
  memset(dp, 0, sizeof dp);
  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++) {
      if (i + l[j] < n)
        dp[i + l[j]] = (dp[i + l[j]] + dp[i] + mod) % mod;
      if (i + r[j] < n)
        dp[i + r[j]] = (dp[i + r[j]] - dp[i] + mod) % mod;
    }
  }
  cout << dp[n - 1] % mod;
  return 0;
}


// #include<atcoder/all>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;
// using namespace atcoder;

#define ll long long
#define pal pair<ll, ll>
#define pad pair<double, double>
#define PB push_back
#define MP make_pair
#define F first
#define S second

const ll MOD = 998244353;
const ll INF = 1e18;
const double EPS = 1e-8;

template <typename T, typename U> bool chmax(T &max, const U &x) {
  if (max < x) {
    max = x;
    return true;
  }
  return false;
}

template <typename T, typename U> bool chmin(T &min, const U &x) {
  if (min > x) {
    min = x;
    return true;
  }
  return false;
}

int main() {
  ll n, k;
  cin >> n >> k;
  set<ll> ivl;
  vector<ll> dp(n + 1, 0);
  for (ll i = 0; i < k; i++) {
    ll l, r;
    cin >> l >> r;
    for (ll j = l; j <= r; j++) {
      ivl.insert(j);
    }
  }
  dp[1] = 1;
  for (ll i = 2; i <= n; i++) {
    for (auto j : ivl) {
      if (i - j > 0) {
        dp[i] += dp[i - j];
        dp[i] %= MOD;
      }
    }
  }
  cout << dp[n] << endl;
}

// #include<atcoder/all>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;
// using namespace atcoder;

#define ll long long
#define pal pair<ll, ll>
#define pad pair<double, double>
#define PB push_back
#define MP make_pair
#define F first
#define S second

const ll MOD = 998244353;
const ll INF = 1e18;
const double EPS = 1e-8;

template <typename T, typename U> bool chmax(T &max, const U &x) {
  if (max < x) {
    max = x;
    return true;
  }
  return false;
}

template <typename T, typename U> bool chmin(T &min, const U &x) {
  if (min > x) {
    min = x;
    return true;
  }
  return false;
}

int main() {
  ll n, k;
  cin >> n >> k;
  vector<pal> ivl;
  vector<ll> dp(n + 1, 0);
  vector<ll> ruiwa(n + 1, 0);
  for (ll i = 0; i < k; i++) {
    ll l, r;
    cin >> l >> r;
    ivl.PB(MP(l, r));
  }
  dp[1] = 1;
  ruiwa[1] = 1;
  for (ll i = 2; i <= n; i++) {
    for (pal p : ivl) {
      if (i - p.F < 0) {
        continue;
      }
      ll hiku = ruiwa[0];
      if (i - p.S > 0) {
        hiku = ruiwa[i - p.S - 1];
      }
      dp[i] = dp[i] + ruiwa[i - p.F] - hiku;
      dp[i] %= MOD;
      if (dp[i] < 0)
        dp[i] += MOD;
    }
    ruiwa[i] = ruiwa[i - 1] + dp[i];
    ruiwa[i] %= MOD;
  }
  cout << dp[n] << endl;
}


#include <bits/stdc++.h>
// #include <atcoder/all>
#define FOR(i, a, n) for (int(i) = (int)(a); (i) < (int)(n); ++(i))
#define FORe(i, a, n) for (int(i) = (int)(a); (i) <= (int)(n); ++(i))
#define rFOR(i, a, n) for (int(i) = (int)(n)-1; (i) >= (int)(a); --(i))
#define rFORe(i, a, n) for (int(i) = (int)(n); (i) >= (int)(a); --(i))
#define REP(i, n) FOR((i), 0, (n))
#define REPe(i, n) FORe((i), 1, (n))
#define REPo(i, n) FORe((i), 0, (n))
#define rREP(i, n) rFOR((i), 0, (n))
#define rREPe(i, n) rFORe((i), 1, (n))
#define rREPo(i, n) rFORe((i), 0, (n))
#define rep(i, n) FOR((i), 0, (n))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define fi first
#define se second
#define dup(x, y) (((x) + (y)-1) / (y))
#define vc(T) vector<T>
#define vv(T) vc(vc(T))
using namespace std;
// using namespace atcoder;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using pll = pair<ll, ll>;
using T = tuple<int, int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using vp = vector<P>;
using vt = vector<T>;

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

// auto mod int
// const int mod = 1000000007;
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, const 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;
  vp lr(k);
  REP(i, k) cin >> lr[i].first >> lr[i].second;
  vc(mint) dp(n + 1);
  vl imo(n);
  dp[0] = 1;
  mint sum = 0;
  REP(i, n) {
    sum += dp[i];
    REP(j, k) {
      int l = min(lr[j].first, n);
      int r = min(lr[j].second + 1, n);
      dp[i + l] += sum;
      dp[i + r] -= sum;
    }
    // REPo(t, n) printf("%lld%c", dp[t], (t==n ? '\\n' : ' '));
  }

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

  return 0;
}

#include <bits/stdc++.h>
// #include <atcoder/all>
#define FOR(i, a, n) for (int(i) = (int)(a); (i) < (int)(n); ++(i))
#define FORe(i, a, n) for (int(i) = (int)(a); (i) <= (int)(n); ++(i))
#define rFOR(i, a, n) for (int(i) = (int)(n)-1; (i) >= (int)(a); --(i))
#define rFORe(i, a, n) for (int(i) = (int)(n); (i) >= (int)(a); --(i))
#define REP(i, n) FOR((i), 0, (n))
#define REPe(i, n) FORe((i), 1, (n))
#define REPo(i, n) FORe((i), 0, (n))
#define rREP(i, n) rFOR((i), 0, (n))
#define rREPe(i, n) rFORe((i), 1, (n))
#define rREPo(i, n) rFORe((i), 0, (n))
#define rep(i, n) FOR((i), 0, (n))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define fi first
#define se second
#define dup(x, y) (((x) + (y)-1) / (y))
#define vc(T) vector<T>
#define vv(T) vc(vc(T))
using namespace std;
// using namespace atcoder;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using pll = pair<ll, ll>;
using T = tuple<int, int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using vp = vector<P>;
using vt = vector<T>;

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

// auto mod int
// const int mod = 1000000007;
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, const 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;
  vp lr(k);
  REP(i, k) cin >> lr[i].first >> lr[i].second;
  vc(mint) dp(n + 1);
  vl imo(n);
  dp[0] = 1;
  mint sum = 0;
  REP(i, n) {
    sum += dp[i];
    REP(j, k) {
      int l = min(i + lr[j].first, n);
      int r = min(i + lr[j].second + 1, n);
      dp[l] += sum;
      dp[r] -= sum;
    }
    // REPo(t, n) printf("%lld%c", dp[t], (t==n ? '\\n' : ' '));
  }

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

  return 0;
}


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

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

  int l, r;
  vector<int> v;

  for (int i = 0; i < k; i++) {
    cin >> l >> r;
    for (int j = l; j <= r; j++) {
      v.push_back(j);
    }
  }
  sort(v.begin(), v.end());
  long long dp[n + 1];
  for (int i = 0; i <= n; i++)
    dp[i] = 0;
  dp[1] = 1;

  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < v.size(); j++) {
      if ((i - v[j]) > 0) {
        dp[i] += (dp[i - v[j]]);
        dp[i] = dp[i] % 998244353;
      } else {
        break;
      }
    }
  }
  cout << dp[n] << endl;
  return 0;
}

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

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

  long long dp[n + 1];
  long long dpsum[n + 1];
  for (int i = 0; i <= n; i++) {
    dp[i] = 0;
    dpsum[i] = 0;
  }
  dp[1] = 1;
  dpsum[1] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < k; j++) {
      int li = i - r[j];
      int ri = i - l[j];
      if (ri < 1)
        continue;
      if (li < 1)
        li = 1;
      dp[i] += (dpsum[ri] - dpsum[li - 1]);
      dp[i] %= 998244353;
    }
    dpsum[i] = (dpsum[i - 1] + dp[i]);
  }
  cout << dp[n] << endl;
  return 0;
}


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

void solve() {

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

  vector<int> v;

  rep(i, k) {
    int x, y;
    cin >> x >> y;

    for (int i = x; i <= y; i++) {
      v.push_back(i);
    }
  }

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

  vector<int> dp(n + 1);
  dp[1] = 1;

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

    for (auto x : v) {
      if (x < i) {
        dp[i] += dp[i - x];
        dp[i] %= mod;
      }
    }
  }
  /*
  rep(i,n){
          cout<<dp[i]<<" " ;
  }
  cout<<"\\n" ;

*/
  cout << dp[n];
}

int main() {

  int y;

  y = 1;
  // cin>>y ;

  while (y--) {

    solve();
  }
}

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
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; }

void solve() {

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

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

  rep(i, k) { cin >> l[i] >> r[i]; }

  vector<mint> dp(n + 1);
  vector<mint> dpsum(n + 1);

  dp[1] = 1;
  dpsum[1] = 1;

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

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

      int li = i - r[j];
      int ri = i - l[j];

      if (ri < 0)
        continue;

      li = max(li, 1);

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

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

  cout << dp[n];
}

int main() {

  int y;

  y = 1;
  // cin>>y ;

  while (y--) {

    solve();
  }
}


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

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

  vector<ll> dp(200010);
  vector<ll> dpsum(20010);
  dp[1] = 1;
  dpsum[1] = 1;

  for (int i = 2; i <= n; i++) {
    rep(j, k) {
      int li = i - r[j];
      int ri = i - l[j];
      if (ri < 0)
        continue;
      li = max(li, 1);
      dp[i] += dpsum[ri] - dpsum[li - 1];
      dp[i] += mod;
      dp[i] %= mod;
    }
    dpsum[i] += dpsum[i - 1] + dp[i];
    dpsum[i] %= mod;
    // cout << dp[i] << " " << dpsum[i] << endl;
  }
  cout << dp[n] << endl;
}

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

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

  vector<ll> dp(n + 1);
  vector<ll> dpsum(n + 1);
  dp[1] = 1;
  dpsum[1] = 1;

  for (int i = 2; i <= n; i++) {
    rep(j, k) {
      int li = i - r[j];
      int ri = i - l[j];
      if (ri < 0)
        continue;
      li = max(li, 1);
      dp[i] += dpsum[ri] - dpsum[li - 1];
      dp[i] += mod;
      dp[i] %= mod;
    }
    dpsum[i] += dpsum[i - 1] + dp[i];
    dpsum[i] %= mod;
    // cout << dp[i] << " " << dpsum[i] << endl;
  }
  cout << dp[n] << endl;
}


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

int main() {
  ll n, k;
  cin >> n >> k;
  vector<pair<ll, ll>> sections;
  for (int i = 0; i < k; ++i) {
    ll l, r;
    cin >> l >> r;
    sections.push_back({l, r});
  }
  vector<ll> f(2 * n + 100, 0), a(2 * n + 100, 0);
  f[1] = 1;
  for (int i = 1; i < 2 * n; ++i) {
    for (int j = 0; j < k; ++j) {
      ll l = sections[j].first;
      ll r = sections[j].second;
      a[i + l] += f[i];
      a[i + r + 1] += (mod - f[i]);
      a[i + l] %= mod;
      a[i + r + 1] %= mod;
    }
    if (i == 1)
      f[i + 1] = a[i + 1];
    else
      f[i + 1] = f[i] + a[i + 1];
    f[i + 1] %= mod;
  }
  cout << f[n] << endl;
}

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

int main() {
  ll n, k;
  cin >> n >> k;
  vector<pair<ll, ll>> sections;
  for (int i = 0; i < k; ++i) {
    ll l, r;
    cin >> l >> r;
    sections.push_back({l, r});
  }
  vector<ll> f(2 * n + 100, 0), a(2 * n + 100, 0);
  f[1] = 1;
  for (int i = 1; i < n; ++i) {
    for (int j = 0; j < k; ++j) {
      ll l = sections[j].first;
      ll r = sections[j].second;
      a[i + l] += f[i];
      a[i + r + 1] += (mod - f[i]);
      a[i + l] %= mod;
      a[i + r + 1] %= mod;
    }
    if (i == 1)
      f[i + 1] = a[i + 1];
    else
      f[i + 1] = f[i] + a[i + 1];
    f[i + 1] %= mod;
  }
  cout << f[n] << endl;
}


#include <bits/stdc++.h>
// g++ -std=c++11

using namespace std;
typedef long long ll;

#define rep(i, n) for (long long i = 0; i < (n); ++i)
#define DIV 998244353

long long dp[200005];

int main() {
  ll N, K;
  cin >> N >> K;
  vector<pair<ll, ll>> LR(K);

  rep(i, K) { cin >> LR[i].first >> LR[i].second; }

  ll cur = 1;
  dp[0] = -1;
  ll ans = -1;

  rep(i, N) {
    rep(j, K) {
      ll l = LR[j].first;
      ll r = LR[j].second;
      dp[i + l - 1] += cur;
      dp[i + l - 1] %= DIV;
      dp[i + r] -= cur;
      dp[i + r] += DIV;
      dp[i + r] %= DIV;
    }
    if (i == N - 1) {
      ans = cur;
    }

    cur += dp[i];
    cur %= DIV;
  }

  cout << ans << endl;
}

#include <bits/stdc++.h>
// g++ -std=c++11

using namespace std;
typedef long long ll;

#define rep(i, n) for (long long i = 0; i < (n); ++i)
#define DIV 998244353

long long dp[200005];

int main() {
  ll N, K;
  cin >> N >> K;
  vector<pair<ll, ll>> LR(K);

  rep(i, K) { cin >> LR[i].first >> LR[i].second; }

  ll cur = 1;
  dp[0] = -1;
  ll ans = -1;

  rep(i, N) {
    rep(j, K) {
      ll l = LR[j].first;
      ll r = LR[j].second;
      if (i + l - 1 <= N) {
        dp[i + l - 1] += cur;
        dp[i + l - 1] %= DIV;
      }
      if (i + r <= N) {
        dp[i + r] -= cur;
        dp[i + r] += DIV;
        dp[i + r] %= DIV;
      }
    }
    if (i == N - 1) {
      ans = cur;
    }

    cur += dp[i];
    cur %= DIV;
  }

  cout << ans << endl;
}


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

const int mod = 998244353;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> l(k), r(k);
  rep(i, k) { cin >> l[i] >> r[i]; }
  set<int> st;
  rep(i, k) {
    for (int j = l[i]; j <= r[i]; j++)
      st.insert(j);
  }
  vector<ll> dp(n + 5);
  dp[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (auto a : st) {
      if (i > a)
        dp[i] += dp[i - a];
      dp[i] %= mod;
    }
  }
  cout << dp[n] << endl;
  return 0;
}

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

const int mod = 998244353;

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


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

const int mod = 998244353;

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

  vector<int> lr;
  rep(i, k) {
    int l, r;
    cin >> l >> r;

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

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

  vector<ll> cnt(n);
  cnt[0] = 1;
  rep(i, n) {
    rep(j, lr.size()) {
      if (lr[j] <= i) {
        // cout << i << " " << lr[j] << endl;
        cnt[i] += cnt[i - lr[j]];
        cnt[i] %= mod;
      } else
        break;
    }
  }

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

  return 0;
}

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

const ll mod = 998244353;
const ll zero = 0;

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

  vector<ll> l(k), r(k);
  rep(i, k) cin >> l[i] >> r[i];

  vector<ll> dp(n + 1);
  dp[1] = 1;
  for (int i = 2; i <= n; i++) {
    ll route = 0;
    rep(j, k) {
      if (i - l[j] > 0) {
        route += dp[i - l[j]] - dp[max(i - r[j] - 1, zero)];
        route %= mod;
      }
    }
    dp[i] = (dp[i - 1] + route) % mod;
    // cout << dp[i] << endl;
  }

  ll ans = dp[n] - dp[n - 1];
  if (ans < 0)
    ans += mod;
  cout << ans << endl;

  return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n - 1); i >= 0; i--)
#define all(x) x.begin(), x.end()
#define br cout << "\\n";
using namespace std;
const long long INF = 1e10;
const long long MOD = 1e9 + 7;
using Graph = vector<vector<ll>>;
using pll = pair<ll, ll>;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
ll ceilll(ll a, ll b) { return (a + b - 1) / b; } // if(a%b == 0) (a/b) + 1
ll get_digit(ll a) {
  ll digit = 0;
  while (a != 0) {
    a /= 10;
    digit++;
  }
  return digit;
} // a != 0
template <typename T> void vecdbg(vector<T> &v) {
  rep(i, v.size()) { cout << v[i] << " "; }
  br;
}
template <typename T> void vecvecdbg(vector<vector<T>> &v) {
  rep(i, v.size()) {
    rep(j, v[i].size()) { cout << v[i][j] << " "; }
    br;
  }
}

// 0 false, 1 true
// string number to int : -48
// a to A : -32
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp
// global vector -> 0 initialization

// https://atcoder.jp/contests/abc172/submissions/14765570
// 20200724
template <long long mod> struct ModInt {
  long long x;
  ModInt() : x(0) {}
  ModInt(long long x) : x(x >= 0 ? x % mod : (mod - -x % mod) % mod) {}
  ModInt &operator+=(const ModInt &p) {
    if ((x += p.x) >= mod)
      x -= mod;
    return *this;
  }
  ModInt &operator-=(const ModInt &p) {
    if ((x += mod - p.x) >= mod)
      x -= mod;
    return *this;
  }
  ModInt &operator*=(const ModInt &p) {
    x = (long long)x * p.x % mod;
    return *this;
  }
  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }
  ModInt &operator^=(long long p) {
    ModInt res = 1;
    for (; p; p >>= 1) {
      if (p & 1)
        res *= *this;
      *this *= *this;
    }
    return *this = res;
  }
  ModInt operator-() const { return ModInt(-x); }
  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
  ModInt operator^(long long p) const { return ModInt(*this) ^= p; }
  bool operator==(const ModInt &p) const { return x == p.x; }
  bool operator!=(const ModInt &p) const { return x != p.x; }
  explicit operator long long() const { return x; }
  ModInt &operator=(const long long p) {
    x = p;
    return *this;
  }
  ModInt inverse() const {
    long long a = x, b = mod, u = 1, v = 0, t;
    while (b > 0) {
      t = a / b;
      a -= t * b;
      std::swap(a, b);
      u -= t * v;
      std::swap(u, v);
    }
    return ModInt(u);
  }
  friend std::ostream &operator<<(std::ostream &stream, const ModInt<mod> &p) {
    return stream << p.x;
  }
  friend std::istream &operator>>(std::istream &stream, ModInt<mod> &a) {
    long long x;
    stream >> x;
    a = ModInt<mod>(x);
    return stream;
  }
};

template <long long mod> struct MComb {
  using mint = ModInt<mod>;
  std::vector<mint> fact;
  std::vector<mint> inv;
  MComb(long long n) { // O(n + log(mod))
    fact = std::vector<mint>(n + 1, 1);
    for (long long i = 1; i <= n; i++)
      fact[i] = fact[i - 1] * mint(i);
    inv.resize(n + 1);
    inv[n] = fact[n] ^ (mod - 2);
    for (long long i = n; i--;)
      inv[i] = inv[i + 1] * mint(i + 1);
  }
  mint ncr(long long n, long r) { return fact[n] * inv[r] * inv[n - r]; }
  mint npr(long n, long r) { return fact[n] * inv[n - r]; }
  mint nhr(long n, long r) {
    assert(n + r - 1 < (long long)fact.size());
    return ncr(n + r - 1, r);
  }
};

template <long long mod> struct MPow {
  using mint = ModInt<mod>;
  mint modpow(mint a, long long n) {
    mint res = 1;
    while (n > 0) {
      if (n & 1) {
        res = res * a;
      }
      a = a * a;
      n >>= 1;
    }
    return res;
  }
};

typedef ModInt<998244353> mint;
MComb<998244353> com(510000);
MPow<998244353> mpow;

mint dp[200010];
mint dp_sum[200010];

int main() {
  std::cout << std::fixed << std::setprecision(15);
  ll n, k;
  cin >> n >> k;
  vector<ll> vec;
  vector<pair<ll, ll>> pv;
  rep(i, k) {
    ll l, r;
    cin >> l >> r;
    pv.emplace_back(l, r);
    /*
    for(ll j = l; j <= r; j++){
        vec.push_back(j);

    }
    */
  }

  sort(all(pv));

  rep(i, pv.size()) {
    for (ll j = pv[i].first; j <= pv[i].second; j++) {
      vec.push_back(j);
    }
  }

  // sort(all(vec));
  /*
  rep(i, vec.size()){
      cout << vec[i] << " ";
  }
  br;
  */

  dp[1] = 1;
  dp_sum[1] = 1;
  for (ll i = 1; i < n + 1; i++) {
    for (ll j = 0; j < pv.size(); j++) {
      if (i - pv[j].first < 0)
        continue;
      if (i - pv[i].second < 1) {
        dp[i] += (dp_sum[i - pv[j].first] - dp_sum[0]);
      } else {
        dp[i] += (dp_sum[i - pv[j].first] - dp_sum[i - pv[j].second - 1]);
      }
    }

    /*
    for(ll j = 0; j < vec.size(); j++){
        if(i - vec[j] < 0){
            //cout << i << " " << j << " c" << endl;
            break;
        }
        dp[i] += dp[i-vec[j]];
    }
    */
    dp_sum[i] = dp_sum[i - 1] + dp[i];
  }

  /*
  rep(i, n+1){
      cout << dp[i] << " ";
  }
  br;
  rep(i, n+1){
      cout << dp_sum[i] << " ";
  }
  br;
  */

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

#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n - 1); i >= 0; i--)
#define all(x) x.begin(), x.end()
#define br cout << "\\n";
using namespace std;
const long long INF = 1e10;
const long long MOD = 1e9 + 7;
using Graph = vector<vector<ll>>;
using pll = pair<ll, ll>;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
ll ceilll(ll a, ll b) { return (a + b - 1) / b; } // if(a%b == 0) (a/b) + 1
ll get_digit(ll a) {
  ll digit = 0;
  while (a != 0) {
    a /= 10;
    digit++;
  }
  return digit;
} // a != 0
template <typename T> void vecdbg(vector<T> &v) {
  rep(i, v.size()) { cout << v[i] << " "; }
  br;
}
template <typename T> void vecvecdbg(vector<vector<T>> &v) {
  rep(i, v.size()) {
    rep(j, v[i].size()) { cout << v[i][j] << " "; }
    br;
  }
}

// 0 false, 1 true
// string number to int : -48
// a to A : -32
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp
// global vector -> 0 initialization

// https://atcoder.jp/contests/abc172/submissions/14765570
// 20200724
template <long long mod> struct ModInt {
  long long x;
  ModInt() : x(0) {}
  ModInt(long long x) : x(x >= 0 ? x % mod : (mod - -x % mod) % mod) {}
  ModInt &operator+=(const ModInt &p) {
    if ((x += p.x) >= mod)
      x -= mod;
    return *this;
  }
  ModInt &operator-=(const ModInt &p) {
    if ((x += mod - p.x) >= mod)
      x -= mod;
    return *this;
  }
  ModInt &operator*=(const ModInt &p) {
    x = (long long)x * p.x % mod;
    return *this;
  }
  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }
  ModInt &operator^=(long long p) {
    ModInt res = 1;
    for (; p; p >>= 1) {
      if (p & 1)
        res *= *this;
      *this *= *this;
    }
    return *this = res;
  }
  ModInt operator-() const { return ModInt(-x); }
  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
  ModInt operator^(long long p) const { return ModInt(*this) ^= p; }
  bool operator==(const ModInt &p) const { return x == p.x; }
  bool operator!=(const ModInt &p) const { return x != p.x; }
  explicit operator long long() const { return x; }
  ModInt &operator=(const long long p) {
    x = p;
    return *this;
  }
  ModInt inverse() const {
    long long a = x, b = mod, u = 1, v = 0, t;
    while (b > 0) {
      t = a / b;
      a -= t * b;
      std::swap(a, b);
      u -= t * v;
      std::swap(u, v);
    }
    return ModInt(u);
  }
  friend std::ostream &operator<<(std::ostream &stream, const ModInt<mod> &p) {
    return stream << p.x;
  }
  friend std::istream &operator>>(std::istream &stream, ModInt<mod> &a) {
    long long x;
    stream >> x;
    a = ModInt<mod>(x);
    return stream;
  }
};

template <long long mod> struct MComb {
  using mint = ModInt<mod>;
  std::vector<mint> fact;
  std::vector<mint> inv;
  MComb(long long n) { // O(n + log(mod))
    fact = std::vector<mint>(n + 1, 1);
    for (long long i = 1; i <= n; i++)
      fact[i] = fact[i - 1] * mint(i);
    inv.resize(n + 1);
    inv[n] = fact[n] ^ (mod - 2);
    for (long long i = n; i--;)
      inv[i] = inv[i + 1] * mint(i + 1);
  }
  mint ncr(long long n, long r) { return fact[n] * inv[r] * inv[n - r]; }
  mint npr(long n, long r) { return fact[n] * inv[n - r]; }
  mint nhr(long n, long r) {
    assert(n + r - 1 < (long long)fact.size());
    return ncr(n + r - 1, r);
  }
};

template <long long mod> struct MPow {
  using mint = ModInt<mod>;
  mint modpow(mint a, long long n) {
    mint res = 1;
    while (n > 0) {
      if (n & 1) {
        res = res * a;
      }
      a = a * a;
      n >>= 1;
    }
    return res;
  }
};

typedef ModInt<998244353> mint;
MComb<998244353> com(510000);
MPow<998244353> mpow;

mint dp[200010];
mint dp_sum[200010];

int main() {
  std::cout << std::fixed << std::setprecision(15);
  ll n, k;
  cin >> n >> k;
  vector<ll> vec;
  vector<pair<ll, ll>> pv;
  rep(i, k) {
    ll l, r;
    cin >> l >> r;
    pv.emplace_back(l, r);
    /*
    for(ll j = l; j <= r; j++){
        vec.push_back(j);

    }
    */
  }

  sort(all(pv));

  rep(i, pv.size()) {
    for (ll j = pv[i].first; j <= pv[i].second; j++) {
      vec.push_back(j);
    }
  }

  // sort(all(vec));
  /*
  rep(i, vec.size()){
      cout << vec[i] << " ";
  }
  br;
  */

  dp[1] = 1;
  dp_sum[1] = 1;
  for (ll i = 1; i < n + 1; i++) {
    for (ll j = 0; j < pv.size(); j++) {
      if (i - pv[j].first < 0)
        continue;
      if (i - pv[j].second < 1) {
        dp[i] += (dp_sum[i - pv[j].first] - dp_sum[0]);
      } else {
        dp[i] += (dp_sum[i - pv[j].first] - dp_sum[i - pv[j].second - 1]);
      }
    }

    /*
    for(ll j = 0; j < vec.size(); j++){
        if(i - vec[j] < 0){
            //cout << i << " " << j << " c" << endl;
            break;
        }
        dp[i] += dp[i-vec[j]];
    }
    */
    dp_sum[i] = dp_sum[i - 1] + dp[i];
  }

  /*
  rep(i, n+1){
      cout << dp[i] << " ";
  }
  br;
  rep(i, n+1){
      cout << dp_sum[i] << " ";
  }
  br;
  */

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


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

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-12;
static const double PI = acos(-1.0);

template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;

#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define dbg(x) true
#endif

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

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

mint dp[200005];

void solve(long long N, long long K, std::vector<long long> L,
           std::vector<long long> R) {
  REP(i, K) {
    dp[L[i]] += 1;
    dp[R[i] + 1] -= 1;
  }
  mint cur = 0;
  FOR(j, 1, N) {
    cur += dp[j];
    REP(i, K) {
      dp[L[i] + j] += cur;
      dp[R[i] + 1 + j] -= cur;
    }
  }
  cout << cur << endl;
}

int main() {
  long long N;
  scanf("%lld", &N);
  long long K;
  scanf("%lld", &K);
  std::vector<long long> L(K);
  std::vector<long long> R(K);
  for (int i = 0; i < K; i++) {
    scanf("%lld", &L[i]);
    scanf("%lld", &R[i]);
  }
  solve(N, K, std::move(L), std::move(R));
  return 0;
}

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

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-12;
static const double PI = acos(-1.0);

template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;

#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define dbg(x) true
#endif

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

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

mint dp[200005];

void solve(long long N, long long K, std::vector<long long> L,
           std::vector<long long> R) {
  REP(i, K) {
    dp[L[i]] += 1;
    dp[R[i] + 1] -= 1;
  }
  mint cur = 0;
  FOR(j, 1, N) {
    cur += dp[j];
    REP(i, K) {
      if (L[i] + j < 200005)
        dp[L[i] + j] += cur;
      if (R[i] + 1 + j < 200005)
        dp[R[i] + 1 + j] -= cur;
    }
  }
  cout << cur << endl;
}

int main() {
  long long N;
  scanf("%lld", &N);
  long long K;
  scanf("%lld", &K);
  std::vector<long long> L(K);
  std::vector<long long> R(K);
  for (int i = 0; i < K; i++) {
    scanf("%lld", &L[i]);
    scanf("%lld", &R[i]);
  }
  solve(N, K, std::move(L), std::move(R));
  return 0;
}


//

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
const ll MOD = 998244353;

ll dp[200001];

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

  vector<int> step;
  for (int i = 0; i < K; i++) {
    int L, R;
    cin >> L >> R;
    for (int j = L; j <= R; j++) {
      step.push_back(j);
    }
  }

  dp[1] = 1;

  for (int i = 1; i < N; i++) {
    for (int s : step) {
      if (i + s > N)
        continue;

      dp[i + s] = (dp[i + s] + dp[i]) % MOD;
    }
  }

  ll ans = dp[N];

  cout << ans << endl;

  return 0;
}

//

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
const ll MOD = 998244353;

ll dp[200001];

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

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

  dp[1] = 1;
  dp[2] = -1;
  ll S = 0;
  for (int i = 1; i <= N; i++) {
    S = (S + dp[i]) % MOD;
    for (auto p : step) {
      int L = p.first;
      int R = p.second;
      if (i + L <= N) {
        dp[i + L] = (dp[i + L] + S) % MOD;
      }
      if (i + R + 1 <= N) {
        dp[i + R + 1] = (dp[i + R + 1] - S + MOD) % MOD;
      }
    }
  }

  ll ans = S;

  cout << ans << endl;

  return 0;
}


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

// https://github.com/atcoder-live/library/blob/master/mint.cpp
const std::int64_t mod = 998244353;
struct mint {
  std::int64_t x; // typedef long long ll;
  mint(std::int64_t 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(std::int64_t 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; }
};
std::istream &operator>>(std::istream &is, const mint &a) { return is >> a.x; }
std::ostream &operator<<(std::ostream &os, const mint &a) { return os << a.x; }

const int MAX_N = 200005;
vector<mint> a(MAX_N, 0);
vector<mint> memo(MAX_N, 0);
vector<pair<ll, ll>> ranges;

int main() {
  ll N, K;
  cin >> N >> K;
  for (int i = 0; i < K; ++i) {
    ll l, r;
    cin >> l >> r;
    ranges.emplace_back(l, r);
  }
  a[0] = 1;
  for (int n = 0; n < N; ++n) {
    if (n > 0)
      memo[n] += memo[n - 1];
    a[n] += memo[n];
    for (const auto &[l, r] : ranges) {
      memo[n + l] += a[n];
      memo[n + r + 1] -= a[n];
    }
  }
  // for (int i = 0; i < 10; ++i) std::cout << i << "\\t"; cout << endl;
  // for (int i = 0; i < 10; ++i) std::cout << a[i] << "\\t"; cout << endl;
  // for (int i = 0; i < 10; ++i) std::cout << memo[i] << "\\t"; cout << endl;
  cout << a[N - 1] << endl;
  return 0;
}

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

// https://github.com/atcoder-live/library/blob/master/mint.cpp
const std::int64_t mod = 998244353;
struct mint {
  std::int64_t x; // typedef long long ll;
  mint(std::int64_t 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(std::int64_t 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; }
};
std::istream &operator>>(std::istream &is, const mint &a) { return is >> a.x; }
std::ostream &operator<<(std::ostream &os, const mint &a) { return os << a.x; }

const ll MAX_N = 200005;
vector<mint> a(MAX_N, 0);
vector<mint> memo(MAX_N, 0);
vector<pair<ll, ll>> ranges;

int main() {
  ll N, K;
  cin >> N >> K;
  for (int i = 0; i < K; ++i) {
    ll l, r;
    cin >> l >> r;
    ranges.emplace_back(l, r);
  }
  a[0] = 1;
  for (int n = 0; n < N; ++n) {
    if (n > 0)
      memo[n] += memo[n - 1];
    a[n] += memo[n];
    for (const auto &[l, r] : ranges) {
      memo[min(n + l, MAX_N - 1)] += a[n];
      memo[min(n + r + 1, MAX_N - 1)] -= a[n];
    }
  }
  // for (int i = 0; i < 10; ++i) std::cout << i << "\\t"; cout << endl;
  // for (int i = 0; i < 10; ++i) std::cout << a[i] << "\\t"; cout << endl;
  // for (int i = 0; i < 10; ++i) std::cout << memo[i] << "\\t"; cout << endl;
  cout << a[N - 1] << endl;
  return 0;
}


#include <bits/stdc++.h>
const int m = 998244353;
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);

  long long n, k, a, b;
  scanf("%lld%lld", &n, &k);
  set<long long> s;
  while (k--) {
    scanf("%lld%lld", &a, &b);
    for (int i = a; i <= b; i++)
      s.insert(i);
  }
  vector<long long> r(n + 1);
  r[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int x : s) {
      if (i - x < 0)
        break;
      r[i] += r[i - x];
      r[i] %= m;
    }
  }
  printf("%lld", r[n]);
}

#include <bits/stdc++.h>
const int m = 998244353;
using namespace std;
long long st[(int)1e6];
long long get(int n) {
  long long x = 0;
  while (n > 0) {
    x += st[n];
    n -= n & (-n);
  }
  return x;
}
void update(int i, int x) {
  while (i < 1e6) {
    st[i] += x;
    i += i & (-i);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);

  memset(st, 0, sizeof(st));
  long long n, k, a, b;
  cin >> n >> k;
  set<pair<int, int>> s;
  while (k--) {
    cin >> a >> b;
    s.insert({a, b});
  }
  update(1, 1);
  long long r = 0;
  for (int i = 2; i <= n; i++) {
    r = 0;
    for (auto x : s) {
      r += get(i - x.first) - get(i - x.second - 1);
      r %= m;
    }
    update(i, r);
  }

  cout << r;
}


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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                                                                \\
  cerr << #v ":[ ";                                                            \\
  for (auto macro_vi : v) {                                                    \\
    cerr << macro_vi << " ";                                                   \\
  }                                                                            \\
  cerr << "]" << endl;
#define ddump(v)                                                               \\
  cerr << #v ":" << endl;                                                      \\
  for (auto macro_row : v) {                                                   \\
    cerr << "[";                                                               \\
    for (auto macro__vi : macro_row) {                                         \\
      cerr << macro__vi << " ";                                                \\
    }                                                                          \\
    cerr << "]" << endl;                                                       \\
  }
using lint = long long;
const int INF = 1e9;
const lint LINF = 1e18;
const double EPS = 1e-10;

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

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

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

  vector<mint> cnt(N + 3, 0);
  cnt[1] = 1;

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

    for (int k = 0; k < K; k++) {
      int left = i + L[k], right = min(N + 1, i + R[k]);
      cnt[left] += cnt[i];
      cnt[right + 1] -= cnt[i];
    }

    cnt[i + 2] += cnt[i + 1];
  }

  cout << cnt[N].x << endl;

  return 0;
}

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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                                                                \\
  cerr << #v ":[ ";                                                            \\
  for (auto macro_vi : v) {                                                    \\
    cerr << macro_vi << " ";                                                   \\
  }                                                                            \\
  cerr << "]" << endl;
#define ddump(v)                                                               \\
  cerr << #v ":" << endl;                                                      \\
  for (auto macro_row : v) {                                                   \\
    cerr << "[";                                                               \\
    for (auto macro__vi : macro_row) {                                         \\
      cerr << macro__vi << " ";                                                \\
    }                                                                          \\
    cerr << "]" << endl;                                                       \\
  }
using lint = long long;
const int INF = 1e9;
const lint LINF = 1e18;
const double EPS = 1e-10;

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

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

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

  vector<mint> cnt(N + 3, 0);
  cnt[1] = 1;

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

    for (int k = 0; k < K; k++) {
      int left = i + L[k], right = min(N + 1, i + R[k]);
      if (N < left) {
        continue;
      }
      cnt[left] += cnt[i];
      cnt[right + 1] -= cnt[i];
    }

    cnt[i + 2] += cnt[i + 1];
  }

  cout << cnt[N].x << endl;

  return 0;
}


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

#define mx 200005
#define ll long long
#define mod 998244353

void IO() {
#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif
}

int ar[mx];
char ch[mx];
int m, n, k, ii;
int mark[mx];
ll dp[mx];
vector<int> v;

ll add(ll a, ll b) {
  a += b;
  if (a >= mod)
    a %= mod;
  return a;
}

ll func(int val) {
  if (val == n)
    return 1;
  if (dp[val] != -1)
    return dp[val];
  ll re = 0;
  for (int u : v) {
    if (val + u > n)
      break;
    re = add(re, func(val + u));
  }
  return dp[val] = re;
}

void solve() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= k; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    for (int j = x; j <= y; j++)
      mark[j] = 1;
  }
  for (int i = 1; i <= n; i++) {
    if (mark[i])
      v.push_back(i);
    dp[i] = -1;
  }
  printf("%lld\\n", func(1));
}

int main() {
  IO();
  int t = 1;
  // scanf("%d",&t);
  while (t--) {
    solve();
  }
  return 0;
}

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

#define mx 200005
#define ll long long
#define mod 998244353

void IO() {
#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif
}

int ar[mx];
char ch[mx];
int m, n, k, ii;
int mark[mx];
ll dp[mx], csum[mx];
vector<int> v;
vector<pair<int, int>> ace;

ll add(ll a, ll b) {
  a += b;
  if (a >= mod)
    a %= mod;
  return a;
}

ll func(int val) {
  if (val == n)
    return 1;
  if (dp[val] != -1)
    return dp[val];
  ll re = 0;
  for (int u : v) {
    if (val + u > n)
      break;
    re = add(re, func(val + u));
  }
  return dp[val] = re;
}

void solve() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= k; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    for (int j = x; j <= y; j++)
      mark[j] = 1;
  }
  int shuru = 1;
  int sesh = 0;
  for (int i = 1; i <= n + 1; i++) {
    if (mark[i]) {
      sesh++;
    } else {
      if (shuru <= sesh) {
        ace.push_back({shuru, sesh});
      }
      shuru = i + 1;
      sesh = i;
    }
  }
  dp[n] = 1;
  csum[n] = 1;
  for (int i = n - 1; i >= 1; i--) {
    int need = n - i;
    for (auto it : ace) {
      if (it.first > need)
        break;
      int st = it.first;
      int en = min(need, it.second);
      ll va = (csum[i + st] - csum[i + en + 1]) % mod;
      if (va < 0)
        va = (va + mod) % mod;
      dp[i] = (dp[i] + va) % mod;
      if (it.second == need)
        break;
    }
    csum[i] += csum[i + 1];
    csum[i] = add(csum[i], dp[i]);
  }
  printf("%lld\\n", dp[1]);
}

int main() {
  IO();
  int t = 1;
  // scanf("%d",&t);
  while (t--) {
    solve();
  }
  return 0;
}


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

#define int long long
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define yn(x) ((x) ? "Yes" : "No")

typedef pair<int, int> ii;
typedef pair<int, ii> iii;

const int siz = 2e5 + 10;
const int SIZ = 1e6 + 10;
const int mod = 998244353;
const int maxx = 2e9;
const int MAXX = 1e18;
const string file = "3";

int n;
vector<int> mov;
int f[siz];

int dp(int pos) {
  if (pos == n) {
    return 1;
  }

  int &res = f[pos];
  if (res != -1) {
    return res;
  }

  res = 0;

  int p = upper_bound(all(mov), n - pos) - mov.begin() - 1;
  for (int i = p; i >= 0; i--) {
    int nxt = pos + mov[i];
    if (nxt <= n) {
      (res += dp(nxt)) %= mod;
    }
  }

  return res;
}

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

  //    freopen ((file + ".inp").c_str(), "r", stdin);
  //    freopen ((file + ".out").c_str(), "w", stdout);

  int k;
  cin >> n >> k;

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

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

  sort(all(mov));

  memset(f, -1, sizeof(f));

  cout << dp(1) << "\\n";

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

  return 0;
}

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

#define int long long
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define yn(x) ((x) ? "Yes" : "No")

typedef pair<int, int> ii;
typedef pair<int, ii> iii;

const int siz = 2e5 + 10;
const int SIZ = 1e6 + 10;
const int mod = 998244353;
const int maxx = 2e9;
const int MAXX = 1e18;
const string file = "3";

int seg[4 * siz];

void update(int id, int st, int ed, int pos, int val) {
  if (st == ed) {
    seg[id] += val;
    return;
  }

  int mid = (st + ed) / 2;
  if (pos <= mid) {
    update(2 * id, st, mid, pos, val);
  } else {
    update(2 * id + 1, mid + 1, ed, pos, val);
  }

  seg[id] = (seg[2 * id] + seg[2 * id + 1]) % mod;
}

int query(int id, int st, int ed, int lt, int rt) {
  if (rt < st || ed < lt) {
    return 0;
  }

  if (lt <= st && ed <= rt) {
    return seg[id];
  }

  int mid = (st + ed) / 2;
  int s1 = query(2 * id, st, mid, lt, rt);
  int s2 = query(2 * id + 1, mid + 1, ed, lt, rt);

  return ((s1 + s2) % mod);
}

ii a[11];

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

  //    freopen ((file + ".inp").c_str(), "r", stdin);
  //    freopen ((file + ".out").c_str(), "w", stdout);

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

  for (int i = 1; i <= k; i++) {
    cin >> a[i].fi >> a[i].se;
  }

  update(1, 1, n, 1, 1);
  for (int i = 2; i <= n; i++) {
    int f = 0;
    for (int j = 1; j <= k; j++) {
      (f += query(1, 1, n, max(i - a[j].se, 0LL), max(i - a[j].fi, 0LL))) %=
          mod;
    }

    update(1, 1, n, i, f);
  }

  cout << query(1, 1, n, n, n) << "\\n";

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

  return 0;
}