#include <algorithm>
#include <complex>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <time.h>
#include <utility>
#include <vector>
using namespace std;
using pii = pair<int, int>;
using ll = long long;
using ld = long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout << "YES" << endl
#define cNO cout << "NO" << endl
#define cYes cout << "Yes" << endl
#define cNo cout << "No" << endl
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define Rep(i, a, b) for (ll i = (a); i < (b); ++i)
#define rrep(i, n) for (ll i = n - 1; i >= 0; i--)
#define rRep(i, a, b) for (ll i = a; i >= b; i--)
#define crep(i) for (char i = 'a'; i <= 'z'; ++i)
#define psortsecond(A, N)                                                      \\
  sort(A, A + N,                                                               \\
       [](const pii &a, const pii &b) { return a.second < b.second; });
#define ALL(x) (x).begin(), (x).end()
#define debug(v)                                                               \\
  cout << #v << ":";                                                           \\
  for (auto x : v) {                                                           \\
    cout << x << ' ';                                                          \\
  }                                                                            \\
  cout << endl;
#define endl '\\n'
int ctoi(const char c) {
  if ('0' <= c && c <= '9')
    return (c - '0');
  return -1;
}
ll gcd(ll a, ll b) { return (b == 0 ? a : gcd(b, a % b)); }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
constexpr ll MOD = 1000000007;
constexpr ll INF = 1000000011;
constexpr ll MOD2 = 998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS = 10e-8;
template <class T, class U> inline bool chmax(T &lhs, const U &rhs) {
  if (lhs < rhs) {
    lhs = rhs;
    return 1;
  }
  return 0;
}
template <class T, class U> inline bool chmin(T &lhs, const U &rhs) {
  if (lhs > rhs) {
    lhs = rhs;
    return 1;
  }
  return 0;
}
template <typename T> istream &operator>>(istream &is, vector<T> &v) {
  for (auto &&x : v)
    is >> x;
  return is;
}
template <typename T, typename U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.first;
  is >> p.second;
  return is;
}
template <typename T, typename U>
ostream &operator>>(ostream &os, const pair<T, U> &p) {
  os << p.first << ' ' << p.second;
  return os;
}
template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = begin(v); i != end(v); ++i) {
    if (i != begin(v))
      os << ' ';
    os << *i;
  }
  return os;
}

// modint

template <std::uint_fast64_t Modulus> class modint {
  using u64 = std::uint_fast64_t;

public:
  u64 a;

  constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  constexpr u64 &value() noexcept { return a; }
  constexpr const u64 &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};

template <typename T, typename E> struct SegmentTree {
  using F = function<T(T, T)>;
  using G = function<T(T, E)>;
  using H = function<E(E, E)>;
  int n, height;
  F f;
  G g;
  H h;
  T ti; // date単位元
  E ei; // lazy単位元
  vector<T> dat;
  vector<E> laz;
  SegmentTree(F f, G g, H h, T ti, E ei) : f(f), g(g), h(h), ti(ti), ei(ei) {}

  void init(int n_) {
    n = 1;
    height = 0;
    while (n < n_)
      n <<= 1, height++;
    dat.assign(2 * n, ti);
    laz.assign(2 * n, ei);
  }
  void build(const vector<T> &v) {
    int n_ = v.size();
    init(n_);
    for (int i = 0; i < n_; i++)
      dat[n + i] = v[i];
    for (int i = n - 1; i; i--)
      dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]);
  }
  inline T reflect(int k) { return laz[k] == ei ? dat[k] : g(dat[k], laz[k]); }
  inline void eval(int k) {
    if (laz[k] == ei)
      return;
    laz[(k << 1) | 0] = h(laz[(k << 1) | 0], laz[k]);
    laz[(k << 1) | 1] = h(laz[(k << 1) | 1], laz[k]);
    dat[k] = reflect(k);
    laz[k] = ei;
  }
  inline void thrust(int k) {
    for (int i = height; i; i--)
      eval(k >> i);
  }
  inline void recalc(int k) {
    while (k >>= 1)
      dat[k] = f(reflect((k << 1) | 0), reflect((k << 1) | 1));
  }
  void update(int a, int b, E x) {
    thrust(a += n);
    thrust(b += n - 1);
    for (int l = a, r = b + 1; l < r; l >>= 1, r >>= 1) {
      if (l & 1)
        laz[l] = h(laz[l], x), l++;
      if (r & 1)
        --r, laz[r] = h(laz[r], x);
    }
    recalc(a);
    recalc(b);
  }
  void set_val(int a, T x) {
    thrust(a += n);
    dat[a] = x;
    laz[a] = ei;
    recalc(a);
  }
  T query(int a, int b) {
    thrust(a += n);
    thrust(b += n - 1);
    T vl = ti, vr = ti;
    for (int l = a, r = b + 1; l < r; l >>= 1, r >>= 1) {
      if (l & 1)
        vl = f(vl, reflect(l++));
      if (r & 1)
        vr = f(reflect(--r), vr);
    }
    return f(vl, vr);
  }
};

signed main() {
  int N, K;
  cin >> N >> K;
  using P = pair<ll, ll>;
  auto f = [](P a, P b) {
    return P(a.first + b.first, a.second + b.second);
  }; //  date同士の演算
  auto g = [](P a, ll b) {
    return P(a.first + b * a.second, a.second);
  };                                         //  lazyからdateへ(bがlazy)
  auto h = [](ll a, ll b) { return a + b; }; // lazyの代入
  SegmentTree<P, ll> rsq(f, g, h, mp(0, 0), 0LL);
  vector<P> V;
  V = vector<P>(N + 1, mp(0, 1));
  V[0].fr = 1;
  rsq.build(V);
  vector<ll> L, R;
  rep(i, K) {
    ll X, Y;
    cin >> X >> Y;
    L.pb(X);
    R.pb(Y);
  }
  rep(i, N) {
    ll T = rsq.query(i, i + 1).fr % MOD2;
    rep(j, K) { rsq.update(i + L[j], i + R[j] + 1, T); }
  }
  cout << rsq.query(N - 1, N).fr % MOD2 << endl;
  // for(int i=0;i<Q;i++){
  //   int c,s,t,x;
  //   cin>>c;
  //   if(c){
  //     cin>>s>>t;
  //     cout<<rsq.query(s-1,t).fr<<endl;   // 0-indexed での[s,t) を入れる
  //   }else{
  //     cin>>s>>t>>x;
  //     rsq.update(s-1,t,x);            // 0-indexed での[s,t) を入れる
  //   }
  // }
}

#include <algorithm>
#include <complex>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <time.h>
#include <utility>
#include <vector>
using namespace std;
using pii = pair<int, int>;
using ll = long long;
using ld = long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout << "YES" << endl
#define cNO cout << "NO" << endl
#define cYes cout << "Yes" << endl
#define cNo cout << "No" << endl
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define Rep(i, a, b) for (ll i = (a); i < (b); ++i)
#define rrep(i, n) for (ll i = n - 1; i >= 0; i--)
#define rRep(i, a, b) for (ll i = a; i >= b; i--)
#define crep(i) for (char i = 'a'; i <= 'z'; ++i)
#define psortsecond(A, N)                                                      \\
  sort(A, A + N,                                                               \\
       [](const pii &a, const pii &b) { return a.second < b.second; });
#define ALL(x) (x).begin(), (x).end()
#define debug(v)                                                               \\
  cout << #v << ":";                                                           \\
  for (auto x : v) {                                                           \\
    cout << x << ' ';                                                          \\
  }                                                                            \\
  cout << endl;
#define endl '\\n'
int ctoi(const char c) {
  if ('0' <= c && c <= '9')
    return (c - '0');
  return -1;
}
ll gcd(ll a, ll b) { return (b == 0 ? a : gcd(b, a % b)); }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
constexpr ll MOD = 1000000007;
constexpr ll INF = 1000000011;
constexpr ll MOD2 = 998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS = 10e-8;
template <class T, class U> inline bool chmax(T &lhs, const U &rhs) {
  if (lhs < rhs) {
    lhs = rhs;
    return 1;
  }
  return 0;
}
template <class T, class U> inline bool chmin(T &lhs, const U &rhs) {
  if (lhs > rhs) {
    lhs = rhs;
    return 1;
  }
  return 0;
}
template <typename T> istream &operator>>(istream &is, vector<T> &v) {
  for (auto &&x : v)
    is >> x;
  return is;
}
template <typename T, typename U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.first;
  is >> p.second;
  return is;
}
template <typename T, typename U>
ostream &operator>>(ostream &os, const pair<T, U> &p) {
  os << p.first << ' ' << p.second;
  return os;
}
template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = begin(v); i != end(v); ++i) {
    if (i != begin(v))
      os << ' ';
    os << *i;
  }
  return os;
}

// modint

template <std::uint_fast64_t Modulus> class modint {
  using u64 = std::uint_fast64_t;

public:
  u64 a;

  constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  constexpr u64 &value() noexcept { return a; }
  constexpr const u64 &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};

template <typename T, typename E> struct SegmentTree {
  using F = function<T(T, T)>;
  using G = function<T(T, E)>;
  using H = function<E(E, E)>;
  int n, height;
  F f;
  G g;
  H h;
  T ti; // date単位元
  E ei; // lazy単位元
  vector<T> dat;
  vector<E> laz;
  SegmentTree(F f, G g, H h, T ti, E ei) : f(f), g(g), h(h), ti(ti), ei(ei) {}

  void init(int n_) {
    n = 1;
    height = 0;
    while (n < n_)
      n <<= 1, height++;
    dat.assign(2 * n, ti);
    laz.assign(2 * n, ei);
  }
  void build(const vector<T> &v) {
    int n_ = v.size();
    init(n_);
    for (int i = 0; i < n_; i++)
      dat[n + i] = v[i];
    for (int i = n - 1; i; i--)
      dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]);
  }
  inline T reflect(int k) { return laz[k] == ei ? dat[k] : g(dat[k], laz[k]); }
  inline void eval(int k) {
    if (laz[k] == ei)
      return;
    laz[(k << 1) | 0] = h(laz[(k << 1) | 0], laz[k]);
    laz[(k << 1) | 1] = h(laz[(k << 1) | 1], laz[k]);
    dat[k] = reflect(k);
    laz[k] = ei;
  }
  inline void thrust(int k) {
    for (int i = height; i; i--)
      eval(k >> i);
  }
  inline void recalc(int k) {
    while (k >>= 1)
      dat[k] = f(reflect((k << 1) | 0), reflect((k << 1) | 1));
  }
  void update(int a, int b, E x) {
    thrust(a += n);
    thrust(b += n - 1);
    for (int l = a, r = b + 1; l < r; l >>= 1, r >>= 1) {
      if (l & 1)
        laz[l] = h(laz[l], x), l++;
      if (r & 1)
        --r, laz[r] = h(laz[r], x);
    }
    recalc(a);
    recalc(b);
  }
  void set_val(int a, T x) {
    thrust(a += n);
    dat[a] = x;
    laz[a] = ei;
    recalc(a);
  }
  T query(int a, int b) {
    thrust(a += n);
    thrust(b += n - 1);
    T vl = ti, vr = ti;
    for (int l = a, r = b + 1; l < r; l >>= 1, r >>= 1) {
      if (l & 1)
        vl = f(vl, reflect(l++));
      if (r & 1)
        vr = f(reflect(--r), vr);
    }
    return f(vl, vr);
  }
};

signed main() {
  ll N, K;
  cin >> N >> K;
  using P = pair<ll, ll>;
  auto f = [](P a, P b) {
    return P(a.first + b.first, a.second + b.second);
  }; //  date同士の演算
  auto g = [](P a, ll b) {
    return P(a.first + b * a.second, a.second);
  };                                         //  lazyからdateへ(bがlazy)
  auto h = [](ll a, ll b) { return a + b; }; // lazyの代入
  SegmentTree<P, ll> rsq(f, g, h, mp(0, 0), 0LL);
  vector<P> V;
  V = vector<P>(N + 5, mp(0, 1));
  V[0].fr = 1;
  rsq.build(V);
  vector<ll> L, R;
  rep(i, K) {
    ll X, Y;
    cin >> X >> Y;
    L.pb(X);
    R.pb(Y);
  }
  rep(i, N) {
    ll T = rsq.query(i, i + 1).fr % MOD2;
    rep(j, K) {
      if (i + L[j] < N) {
        rsq.update(i + L[j], (min(i + R[j] + 1ll, N + 1)), T);
      }
    }
  }
  cout << rsq.query(N - 1, N).fr % MOD2 << endl;
  // for(int i=0;i<Q;i++){
  //   int c,s,t,x;
  //   cin>>c;
  //   if(c){
  //     cin>>s>>t;
  //     cout<<rsq.query(s-1,t).fr<<endl;   // 0-indexed での[s,t) を入れる
  //   }else{
  //     cin>>s>>t>>x;
  //     rsq.update(s-1,t,x);            // 0-indexed での[s,t) を入れる
  //   }
  // }
}


#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iosfwd>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
#pragma GCC optimize("-O3")
using namespace std;
#define fastio                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);                                                              \\
  cerr.tie(NULL);
#define tolower(s) transform(s.begin(), s.end(), s.begin(), ::tolower);
#define toupper(s) transform(s.begin(), s.end(), s.begin(), ::toupper);
#define ll long long int
ll max(ll a, ll b) { return a > b ? a : b; }
ll gcd(ll a, ll b) {
  if (a == 0) {
    return b;
  }
  return b == 0 ? a : gcd(b, a % b);
}
#define case(i) cout << "Case #" << i << ": ";
#define debug(args...)                                                         \\
  {                                                                            \\
    string _s = #args;                                                         \\
    replace(_s.begin(), _s.end(), ',', ' ');                                   \\
    stringstream _ss(_s);                                                      \\
    istream_iterator<string> _it(_ss);                                         \\
    err(_it, args);                                                            \\
    cerr << '\\n';                                                              \\
  }
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << "[ " << *it << " = " << a << " ]";
  err(++it, args...);
}
#define pii pair<ll, ll>
#define pb push_back
#define PRECISION 10
const ll inf = 9223372036854775800;
const int MAXN = 100001;
const int LOGN = 22;
const int MAXBIT = 62;
const long double PI = 3.141592653589793;
const int DIGITSIZE = 18;
ll mod = 1e9 + 7;
ll MOD = 998244353;
int x4[] = {1, -1, 0, 0};
int y4[] = {0, 0, 1, -1};
int x8[] = {1, 1, 1, -1, -1, -1, 0, 0};
int y8[] = {1, 0, -1, 1, 0, -1, 1, -1};
bool takeTestCases = 0;
bool printCaseNo = 0;
ll bit[MAXN + 1];
void update(int pos, int val) {
  while (pos <= MAXN) {
    bit[pos] += val % MOD;
    bit[pos] %= MOD;
    pos += (pos & -pos);
  }
}
int query(int pos) {
  ll ans = 0;
  while (pos > 0) {
    ans += bit[pos] % MOD;
    ans %= MOD;
    pos -= (pos & -pos);
  }
  return ans;
}
void getac(int T) {
  int n, k;
  cin >> n >> k;
  vector<pii> q;
  for (int i = 0; i < k; i++) {
    int l, r;
    cin >> l >> r;
    q.pb({l, r});
  }
  ll dp[n + 1];
  for (int i = 0; i <= n; i++) {
    dp[i] = 0;
  }
  dp[0] = 0;
  dp[1] = 1;
  update(1, 1);
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < k; j++) {
      int l = q[j].first;
      int r = q[j].second;
      l = max(i - l, 0);
      r = max(i - r - 1, 0);
      // cout << j << ' ' << l << ' ' << r << '\\n';
      dp[i] += query(l);
      dp[i] -= query(r);
      dp[i] += MOD;
      dp[i] %= MOD;
    }
    update(i, dp[i]);
    // cout << '\\n';
  }
  cout << dp[n] << '\\n';
}
int main() {

  fastio;
  int t = 1;
  if (takeTestCases) {
    cin >> t;
  }
  int t_t = 1;
  while (t--) {
    if (printCaseNo)
                case (t_t);
		getac(t_t);
		t_t++;
	}
	cerr << "Total time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\\n';
	return 0;
}

#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iosfwd>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
#pragma GCC optimize("-O3")
using namespace std;
#define fastio                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);                                                              \\
  cerr.tie(NULL);
#define tolower(s) transform(s.begin(), s.end(), s.begin(), ::tolower);
#define toupper(s) transform(s.begin(), s.end(), s.begin(), ::toupper);
#define ll long long int
ll max(ll a, ll b) { return a > b ? a : b; }
ll gcd(ll a, ll b) {
  if (a == 0) {
    return b;
  }
  return b == 0 ? a : gcd(b, a % b);
}
#define case(i) cout << "Case #" << i << ": ";
#define debug(args...)                                                         \\
  {                                                                            \\
    string _s = #args;                                                         \\
    replace(_s.begin(), _s.end(), ',', ' ');                                   \\
    stringstream _ss(_s);                                                      \\
    istream_iterator<string> _it(_ss);                                         \\
    err(_it, args);                                                            \\
    cerr << '\\n';                                                              \\
  }
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << "[ " << *it << " = " << a << " ]";
  err(++it, args...);
}
#define pii pair<ll, ll>
#define pb push_back
#define PRECISION 10
const ll inf = 9223372036854775800;
const int MAXN = 200005;
const int LOGN = 22;
const int MAXBIT = 62;
const long double PI = 3.141592653589793;
const int DIGITSIZE = 18;
ll mod = 1e9 + 7;
ll MOD = 998244353;
int x4[] = {1, -1, 0, 0};
int y4[] = {0, 0, 1, -1};
int x8[] = {1, 1, 1, -1, -1, -1, 0, 0};
int y8[] = {1, 0, -1, 1, 0, -1, 1, -1};
bool takeTestCases = 0;
bool printCaseNo = 0;
ll bit[MAXN + 1];
void update(int pos, int val) {
  while (pos <= MAXN) {
    bit[pos] += val % MOD;
    bit[pos] %= MOD;
    pos += (pos & -pos);
  }
}
int query(int pos) {
  ll ans = 0;
  while (pos > 0) {
    ans += bit[pos] % MOD;
    ans %= MOD;
    pos -= (pos & -pos);
  }
  return ans;
}
void getac(int T) {
  int n, k;
  cin >> n >> k;
  vector<pii> q;
  for (int i = 0; i < k; i++) {
    int l, r;
    cin >> l >> r;
    q.pb({l, r});
  }
  ll dp[n + 1];
  for (int i = 0; i <= n; i++) {
    dp[i] = 0;
  }
  dp[0] = 0;
  dp[1] = 1;
  update(1, 1);
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < k; j++) {
      int l = q[j].first;
      int r = q[j].second;
      l = max(i - l, 0);
      r = max(i - r - 1, 0);
      // cout << j << ' ' << l << ' ' << r << '\\n';
      dp[i] += query(l);
      dp[i] -= query(r);
      dp[i] += MOD;
      dp[i] %= MOD;
    }
    update(i, dp[i]);
    // cout << '\\n';
  }
  cout << dp[n] << '\\n';
}
int main() {

  fastio;
  int t = 1;
  if (takeTestCases) {
    cin >> t;
  }
  int t_t = 1;
  while (t--) {
    if (printCaseNo)
                case (t_t);
		getac(t_t);
		t_t++;
	}
	cerr << "Total time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\\n';
	return 0;
}


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

const int N = (int)2e5 + 10;
ll dp[N];
vector<pair<int, int>> vec;

ll solve(int curr, int tar) {

  if (curr > tar) {
    return 0;
  }

  if (curr == tar) {
    return 1;
  }
  if (dp[curr] != -1) {
    return dp[curr];
  }
  ll res = 0;
  for (int i = 0; i < (int)vec.size(); i++) {

    for (int j = vec[i].first; j <= vec[i].second; j++) {
      res += solve(curr + j, tar);
      res %= mod;
    }
  }
  dp[curr] = (res + mod) % mod;
  return dp[curr];
}

int main() {
  int n, k;
  cin >> n >> k;
  memset(dp, -1, sizeof(dp));
  unordered_set<int> st;
  for (int i = 0; i < k; i++) {

    int l, r;
    cin >> l >> r;
    vec.push_back({l, r});
  }
  ll res = solve(1, n);
  res = (res + mod) % mod;
  cout << res << endl;
}

#include <bits/stdc++.h>

#define ll long long
#define pb push_back
#define all(x) (x).begin(), (x).end()
using namespace std;

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


#include <iostream>
#include <set>

#define N_MAX (2 * 1000)
#define MOD (998244353)

unsigned int dp[N_MAX];

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

  int L[10], R[10];
  for (int i = 0; i < K; i++) {
    std::cin >> L[i] >> R[i];
  }
  dp[0] = 1;
  for (int i = 1; i < N; i++) {
    dp[i] = dp[i - 1];
    for (int k = 0; k < K; k++) {
      if (i - L[k] >= 0 && i - R[k] - 1 >= 0) {
        dp[i] += (MOD + dp[i - L[k]] - dp[i - R[k] - 1]) % MOD;
      } else if (i - L[k] >= 0) {
        dp[i] += dp[i - L[k]];
      }
      dp[i] %= MOD;
    }
  }
  std::cout << (MOD + dp[N - 1] - dp[N - 2]) % MOD << std::endl;
  return 0;
}

#include <iostream>
#include <set>

#define N_MAX (2 * 100000)
#define MOD (998244353)

unsigned int dp[N_MAX];

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

  int L[10], R[10];
  for (int i = 0; i < K; i++) {
    std::cin >> L[i] >> R[i];
  }
  dp[0] = 1;
  for (int i = 1; i < N; i++) {
    dp[i] = dp[i - 1];
    for (int k = 0; k < K; k++) {
      if (i - L[k] >= 0 && i - R[k] - 1 >= 0) {
        dp[i] += (MOD + dp[i - L[k]] - dp[i - R[k] - 1]) % MOD;
      } else if (i - L[k] >= 0) {
        dp[i] += dp[i - L[k]];
      }
      dp[i] %= MOD;
    }
  }
  std::cout << (MOD + dp[N - 1] - dp[N - 2]) % MOD << std::endl;
  return 0;
}


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

const long long MOD = 998244353;
long long N, K, l[11], r[11], memo[200010], prefix[400010];

void Input() {
  cin >> N >> K;
  for (long long i = 1; i <= K; i++) {
    cin >> l[i] >> r[i];
  }
}

void Solve() {
  memset(prefix, 0, sizeof prefix);
  prefix[N] = 1;
  memo[N] = 1;
  for (long long i = N - 1; i >= 1; i--) {
    long long total = 0;
    for (long long j = 1; j <= K; j++) {
      long long nl = l[i], nr = r[i];
      total += (prefix[i + nl] - prefix[i + nr + 1]) % MOD;
      total = total % MOD;
    }
    memo[i] = total;
    prefix[i] = (prefix[i + 1] + total) % MOD;
  }
  cout << memo[1] << '\\n';
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  Input();
  Solve();
}

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

const long long MOD = 998244353;
long long N, K, l[11], r[11], memo[200010], prefix[400010];

void Input() {
  cin >> N >> K;
  for (long long i = 1; i <= K; i++) {
    cin >> l[i] >> r[i];
  }
}

void Solve() {
  memset(prefix, 0, sizeof prefix);
  prefix[N] = 1;
  memo[N] = 1;
  for (long long i = N - 1; i >= 1; i--) {
    long long total = 0;
    for (long long j = 1; j <= K; j++) {
      long long nl = l[j], nr = r[j];
      total += (prefix[i + nl] - prefix[i + nr + 1] + MOD) % MOD;
      total = total % MOD;
    }
    memo[i] = total;
    prefix[i] = (prefix[i + 1] + total) % MOD;
  }
  cout << memo[1] << '\\n';
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  Input();
  Solve();
}


#include <bits/stdc++.h>
#include <boost/dynamic_bitset.hpp>
using namespace std;
using u64 = uint64_t;
using s64 = int64_t;

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

  u64 mod = 998244353;
  deque<u64> S;
  vector<u64> dp(N);
  dp[0] = 1;

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

  for (u64 i = 0; i < N; i++) {
    u64 c = S.size();
    for (u64 k = 0; k < c; k++) {
      auto d = S.front();
      S.pop_front();
      if (i + d < N) {
        dp[i + d] = (dp[i + d] + dp[i]) % mod;
        S.push_back(d);
      }
    }
  }

  cout << dp[N - 1] << endl;
  return 0;
}

#include <bits/stdc++.h>
#include <boost/dynamic_bitset.hpp>
using namespace std;
using u64 = uint64_t;
using s64 = int64_t;

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

  u64 mod = 998244353;
  vector<pair<u64, u64>> S(K);

  for (u64 i = 0; i < K; i++) {
    u64 L, R;
    cin >> L >> R;
    S[i] = make_pair(L, R);
  }

  vector<u64> sum(N);
  sum[0] = 1;

  for (s64 i = 1; i < N; i++) {
    u64 dp = 0;

    for (const auto &lr : S) {
      s64 R = i - lr.first;
      if (R >= 0) {
        dp = (dp + sum[R]) % mod;
        s64 L = i - lr.second - 1;
        if (L >= 0) {
          dp = (dp >= sum[L]) ? dp - sum[L] : dp + mod - sum[L];
        }
      }
    }

    sum[i] = (sum[i - 1] + dp) % mod;
  }

  u64 ans = (sum[N - 1] >= sum[N - 2]) ? sum[N - 1] - sum[N - 2]
                                       : sum[N - 1] + mod - sum[N - 2];
  cout << ans << 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>;
#define chmax(x, y) x = max(x, y);
#define chmin(x, y) x = min(x, y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;

// 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 {
    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;
  }
};
istream &operator>>(istream &i, mint &a) {
  i >> a.x;
  return i;
}
ostream &operator<<(ostream &o, const mint &a) {
  o << a.x;
  return o;
}

int main() {
  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++) {
    rep(j, k) {
      int li = i - r[j];
      int ri = i - l[i];
      if (ri < 0)
        continue;
      li = max(li, 1);
      dp[i] += dpsum[ri] - dpsum[li - 1];
    }
    dpsum[i] = dpsum[i - 1] + dp[i];
  }
  cout << dp[n] << endl;
  return 0;
}

#include <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>;
#define chmax(x, y) x = max(x, y);
#define chmin(x, y) x = min(x, y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;

// 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 {
    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;
  }
};
istream &operator>>(istream &i, mint &a) {
  i >> a.x;
  return i;
}
ostream &operator<<(ostream &o, const mint &a) {
  o << a.x;
  return o;
}

int main() {
  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++) {
    rep(j, k) {
      int li = i - r[j];
      int ri = i - l[j];
      if (ri < 0)
        continue;
      li = max(li, 1);
      dp[i] += dpsum[ri] - dpsum[li - 1];
    }
    dpsum[i] = dpsum[i - 1] + dp[i];
  }
  cout << dp[n] << endl;
  return 0;
}


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

ll dp[200005];
vector<int> opt;

ll solve(int n) {
  if (dp[n] != -1)
    return dp[n];
  if (n == 0)
    return dp[n] = 1;
  else {
    ll ret = 0;
    for (auto el : opt) {
      if (el <= n) {
        ret = (ret + solve(n - el)) % MOD;
      }
    }
    return dp[n] = ret;
  }
}

int main() {
  rep(i, 200005) dp[i] = -1;

  int n, k;
  cin >> n >> k;
  rep(i, k) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++)
      opt.push_back(j);
  }
  cout << solve(n - 1) << endl;
  // rep(i, 5) cout << dp[i] << endl;

  return 0;
}

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

ll dp[200005];
vector<P> opt;

ll solve(int n) {
  if (dp[n] != -1)
    return dp[n];
  if (n == 0)
    return dp[n] = 1;
  else if (n == 1) {
    int ret = 0;
    for (auto el : opt) {
      if (el.first == 1)
        ret = 1;
    }
    return dp[n] = ret;
  } else {
    ll ret = solve(n - 1);
    for (auto el : opt) {
      if (n - el.first >= 0) {
        if (n - el.second >= 0) {
          ret = ret + solve(n - el.first) - solve(n - el.second);
        } else {
          ret = ret + solve(n - el.first);
        }
      }
      ret = (ret + MOD) % MOD;
    }
    return dp[n] = ret;
  }
}

int main() {
  rep(i, 200005) dp[i] = -1;

  int n, k;
  cin >> n >> k;
  rep(i, k) {
    int l, r;
    cin >> l >> r;
    opt.emplace_back(l, r + 1);
  }
  cout << solve(n - 1) << endl;
  // rep(i, 5) cout << dp[i] << endl;

  return 0;
}


#include <algorithm>
#include <cstdio>
using namespace std;

// Definitions
#define MAXN 210
// #define MAXN 200010
#define MOD 998244353
#define elif else if
typedef long long int64;
#define File(s) freopen(#s ".in", "r", stdin), freopen(#s ".out", "w", stdout)

// Variables
int n, k, l[MAXN], r[MAXN];

// Pynamic Programming
int dp[MAXN], pfxsum[MAXN];
inline void DP() {
  dp[1] = 1;
  for (int cur = 1, begin, end; cur <= n; cur++) {
    for (int idx = 1; idx <= k; idx++) {
      begin = max(1, cur - r[idx]);
      end = max(0, cur - l[idx]);
      // for (int last = begin; last <= end; last++) {
      //   dp[cur] = (dp[cur] + dp[last]) % MOD;
      // }
      if (begin <= end) {
        dp[cur] = dp[cur] + (pfxsum[end] + MOD - pfxsum[begin - 1]) % MOD;
        dp[cur] %= MOD;
      }
    }
    pfxsum[cur] = (pfxsum[cur - 1] + dp[cur]) % MOD;
  }
}

// Functions
inline void Monitor() {
  for (int i = 1; i <= n; i++) {
    printf("%d ", dp[i]);
  }
  puts("");
}
inline void Process() { DP(); }
inline void ReadIn() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= k; i++) {
    scanf("%d %d", l + i, r + i);
  }
}
inline void PrintAns() {
  // Monitor();
  printf("%d\\n", dp[n]);
}

int main() {
#ifndef ONLINE_JUDGE
  File(data);
#endif
  ReadIn();
  Process();
  PrintAns();
  return 0;
}
/*

==== O(n^2) {Diffuse} ====
> dp[1] = 1;
> for (int cur = 1; cur <= n; cur++) {
>   for (int idx = 1; idx <= k; idx++) {
>     for (int add = l[idx]; add <= r[idx]; add++) {
>       dp[cur + add] = (dp[cur + add] + dp[cur]) % MOD;
>     }
>   }
> }
==== O(n^2) {Collect} ===
> dp[1] = 1;
> for (int cur = 1, begin, end; cur <= n; cur++) {
>   for (int idx = 1; idx <= k; idx++) {
>     begin = max(1, cur - r[idx]);
>     end = max(0, cur - l[idx]);
>     for (int last = begin; last <= end; last++) {
>       dp[cur] = (dp[cur] + dp[last]) % MOD;
>     }
>   }
> }

*/

#include <algorithm>
#include <cstdio>
using namespace std;

// Definitions
// #define MAXN 210
#define MAXN 200010
#define MOD 998244353
#define elif else if
typedef long long int64;
#define File(s) freopen(#s ".in", "r", stdin), freopen(#s ".out", "w", stdout)

// Variables
int n, k, l[MAXN], r[MAXN];

// Pynamic Programming
int dp[MAXN], pfxsum[MAXN];
inline void DP() {
  dp[1] = 1;
  for (int cur = 1, begin, end; cur <= n; cur++) {
    for (int idx = 1; idx <= k; idx++) {
      begin = max(1, cur - r[idx]);
      end = max(0, cur - l[idx]);
      // for (int last = begin; last <= end; last++) {
      //   dp[cur] = (dp[cur] + dp[last]) % MOD;
      // }
      if (begin <= end) {
        dp[cur] = dp[cur] + (pfxsum[end] + MOD - pfxsum[begin - 1]) % MOD;
        dp[cur] %= MOD;
      }
    }
    pfxsum[cur] = (pfxsum[cur - 1] + dp[cur]) % MOD;
  }
}

// Functions
inline void Monitor() {
  for (int i = 1; i <= n; i++) {
    printf("%d ", dp[i]);
  }
  puts("");
}
inline void Process() { DP(); }
inline void ReadIn() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= k; i++) {
    scanf("%d %d", l + i, r + i);
  }
}
inline void PrintAns() {
  // Monitor();
  printf("%d\\n", dp[n]);
}

int main() {
#ifndef ONLINE_JUDGE
  File(data);
#endif
  ReadIn();
  Process();
  PrintAns();
  return 0;
}
/*

==== O(n^2) {Diffuse} ====
> dp[1] = 1;
> for (int cur = 1; cur <= n; cur++) {
>   for (int idx = 1; idx <= k; idx++) {
>     for (int add = l[idx]; add <= r[idx]; add++) {
>       dp[cur + add] = (dp[cur + add] + dp[cur]) % MOD;
>     }
>   }
> }
==== O(n^2) {Collect} ===
> dp[1] = 1;
> for (int cur = 1, begin, end; cur <= n; cur++) {
>   for (int idx = 1; idx <= k; idx++) {
>     begin = max(1, cur - r[idx]);
>     end = max(0, cur - l[idx]);
>     for (int last = begin; last <= end; last++) {
>       dp[cur] = (dp[cur] + dp[last]) % MOD;
>     }
>   }
> }

*/


/*
ID: Trump
TASK:
LANG: C++
*/
/* LANG can be C++11 or C++14 for those more recent releases */
#include <algorithm>
#include <cmath>
#include <cstring>
#include <fstream>
#include <iostream>
using namespace std;
typedef long long ll;
typedef long double lb;
// #define MARK
const ll losn = 1e6 + 5;
const ll maxn = 1e5 + 5;
const ll minn = 1e3 + 5;
const ll tiny = 1e2 + 5;
const ll inf = 1e9;
const ll mod = 1e9 + 7;
const ll hmod = 4698571;
ll u[11], v[11];
ll tot = 0;
ll mods = 998244353;
ll tree[maxn * 2 * 4];

ll push_up(ll rt) {
  tree[rt] = tree[rt << 1] + tree[rt << 1 | 1];
  tree[rt] %= mods;
}

void build(ll l, ll r, ll rt) {
  if (l == r) {
    return;
  }
  ll mid = (l + r) >> 1;
  if (l <= mid) {
    build(l, mid, rt << 1);
  }
  if (r > mid) {
    build(mid + 1, r, rt << 1 | 1);
  }
  push_up(rt);
}

ll query(ll a, ll b, ll l, ll r, ll rt) {
  if (a <= l && r <= b) {
    return tree[rt] % mods;
  }
  ll mid = (l + r) >> 1;
  ll sums = 0;
  if (a <= mid) {
    sums += query(a, b, l, mid, rt << 1);
  }
  if (b > mid) {
    sums += query(a, b, mid + 1, r, rt << 1 | 1);
  }
  sums %= mods;
  push_up(rt);
  return sums;
}

void update(ll x, ll sums, ll l, ll r, ll rt) {
  if (l == r) {
    tree[rt] = sums;
    return;
  }
  ll mid = (l + r) >> 1;
  if (x <= mid) {
    update(x, sums, l, mid, rt << 1);
  } else {
    update(x, sums, mid + 1, r, rt << 1 | 1);
  }
  push_up(rt);
}

int main() {
  // #ifdef MARK
  //     freopen("input.in", "r", stdin);
  //     freopen("ouput.out", "w", stdout);
  //     freopen("input.in", "r", stdin);
  //     freopen("ouput.out", "w", stdout);
  // #endif
  ll n, k;
  cin >> n >> k;
  for (ll i = 1; i <= k; i++) {
    cin >> u[i] >> v[i];
  }
  update(1, 1, 1, n, 1);
  for (ll i = 2; i <= n; i++) {
    ll sums = 0;
    for (ll j = 1; j <= k; j++) {
      if (u[j] >= i)
        continue;
      ll a = i - u[j], b = max((ll)1, i - v[j]);
      if (a >= 1 && b >= 1 && b <= a) {
        sums += query(b, a, 1, n, 1);
        sums %= mods;
      }
    }
    update(i, sums, 1, n, 1);
  }
  cout << query(n, n, 1, n, 1) % mods << endl;
  return 0;
}

/*
ID: Trump
TASK:
LANG: C++
*/
/* LANG can be C++11 or C++14 for those more recent releases */
#include <algorithm>
#include <cmath>
#include <cstring>
#include <fstream>
#include <iostream>
using namespace std;
typedef long long ll;
typedef long double lb;
// #define MARK
const ll losn = 1e6 + 5;
const ll maxn = 1e5 + 5;
const ll minn = 1e3 + 5;
const ll tiny = 1e2 + 5;
const ll inf = 1e9;
const ll mod = 1e9 + 7;
const ll hmod = 4698571;
ll u[11], v[11];
ll tot = 0;
ll mods = 998244353;
ll tree[(maxn * 2) << 2];

void push_up(ll rt) {
  tree[rt] = tree[rt << 1] + tree[rt << 1 | 1];
  tree[rt] %= mods;
}

void build(ll l, ll r, ll rt) {
  if (l == r) {
    return;
  }
  ll mid = (l + r) >> 1;
  if (l <= mid) {
    build(l, mid, rt << 1);
  }
  if (r > mid) {
    build(mid + 1, r, rt << 1 | 1);
  }
  push_up(rt);
}

ll query(ll a, ll b, ll l, ll r, ll rt) {
  if (a <= l && r <= b) {
    return tree[rt] % mods;
  }
  ll mid = (l + r) >> 1;
  ll sums = 0;
  if (a <= mid) {
    sums += query(a, b, l, mid, rt << 1);
  }
  if (b > mid) {
    sums += query(a, b, mid + 1, r, rt << 1 | 1);
  }
  sums %= mods;
  push_up(rt);
  return sums;
}

void update(ll x, ll sums, ll l, ll r, ll rt) {
  if (l == r) {
    tree[rt] = sums;
    return;
  }
  ll mid = (l + r) >> 1;
  if (x <= mid) {
    update(x, sums, l, mid, rt << 1);
  }
  if (x > mid) {
    update(x, sums, mid + 1, r, rt << 1 | 1);
  }
  push_up(rt);
}

int main() {
  // #ifdef MARK
  //     freopen("input.in", "r", stdin);
  //     freopen("ouput.out", "w", stdout);
  //     freopen("input.in", "r", stdin);
  //     freopen("ouput.out", "w", stdout);
  // #endif
  ll n, k;
  cin >> n >> k;
  for (ll i = 1; i <= k; i++) {
    cin >> u[i] >> v[i];
  }
  update(1, 1, 1, n, 1);
  for (ll i = 2; i <= n; i++) {
    ll sums = 0;
    for (ll j = 1; j <= k; j++) {
      if (u[j] >= i)
        continue;
      ll a = i - u[j], b = max((ll)1, i - v[j]);
      if (a >= 1 && b >= 1 && b <= a) {
        sums += query(b, a, 1, n, 1);
        sums %= mods;
      }
    }
    update(i, sums, 1, n, 1);
  }
  cout << query(n, n, 1, n, 1) % mods << endl;
  return 0;
}


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

#define en "\\n"
#define INF (int)9e18
#define HELL 998244353LL
#define int long long
#define double long double
#define uint unsigned long long
#define pii pair<int, int>
#define pb push_back
#define fs first
#define sc second
#define size(a) (int)a.size()
#define deb(x) cerr << #x << " => " << x << en
#define debp(a)                                                                \\
  cerr << #a << " => "                                                         \\
       << "(" << a.fs << ", " << a.sc << ") " << en;
#define deba(x)                                                                \\
  cerr << #x << en;                                                            \\
  for (auto a : x)                                                             \\
    cerr << a << " ";                                                          \\
  cerr << en;
#define debpa(x)                                                               \\
  cerr << #x << en;                                                            \\
  for (auto a : x)                                                             \\
    cerr << "(" << a.fs << ", " << a.sc << ") ";                               \\
  cerr << en;
#define debm(x)                                                                \\
  cerr << #x << en;                                                            \\
  for (auto a : x) {                                                           \\
    for (auto b : a)                                                           \\
      cerr << b << " ";                                                        \\
    cerr << en;                                                                \\
  }
#define getMat(x, n, m, val) vector<vector<int>> x(n, vector<int>(m, val))
#define fastio                                                                 \\
  ios_base ::sync_with_stdio(false);                                           \\
  cin.tie(nullptr);                                                            \\
  cout.tie(nullptr);
#define pout cout << fixed << setprecision(10)
int fastpow(int a, int b, int m = HELL) {
  int res = 1;
  a %= m;
  while (b > 0) {
    if (b & 1)
      res = (res * a) % m;
    a = (a * a) % m;
    b >>= 1;
  }
  return res;
}
#define inv(a) fastpow(a, HELL - 2)
#define mul(a, b) ((a % HELL) * (b % HELL)) % HELL

int n;
const int maxN = 1e5 + 5;
int tree[maxN];

void update(int index, int val) {
  while (index <= n) {
    tree[index] = (tree[index] + val) % HELL;
    index += (index & -index);
  }
}

int read(int index) {
  int sum = 0;
  while (index) {
    sum = (sum + tree[index]) % HELL;
    index -= (index & -index);
  }
  return sum;
}

int getSum(int low, int high) {
  if (high <= 0) {
    return 0;
  }
  if (low <= 1) {
    return read(high);
  }
  return (read(high) - read(low - 1) + HELL) % HELL;
}

int32_t main() {
  fastio;
  int k, a, b;
  cin >> n >> k;
  vector<vector<int>> s;
  while (k--) {
    cin >> a >> b;
    s.pb({a, b});
  }
  update(1, 1);
  for (int i = 2; i <= n; i++) {
    for (auto x : s) {
      update(i, getSum(i - x[1], i - x[0]));
    }
  }
  cout << (read(n) - read(n - 1) + HELL) % HELL << endl;
  return 0;
}

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

#define en "\\n"
#define INF (int)9e18
#define HELL 998244353LL
#define int long long
#define double long double
#define uint unsigned long long
#define pii pair<int, int>
#define pb push_back
#define fs first
#define sc second
#define size(a) (int)a.size()
#define deb(x) cerr << #x << " => " << x << en
#define debp(a)                                                                \\
  cerr << #a << " => "                                                         \\
       << "(" << a.fs << ", " << a.sc << ") " << en;
#define deba(x)                                                                \\
  cerr << #x << en;                                                            \\
  for (auto a : x)                                                             \\
    cerr << a << " ";                                                          \\
  cerr << en;
#define debpa(x)                                                               \\
  cerr << #x << en;                                                            \\
  for (auto a : x)                                                             \\
    cerr << "(" << a.fs << ", " << a.sc << ") ";                               \\
  cerr << en;
#define debm(x)                                                                \\
  cerr << #x << en;                                                            \\
  for (auto a : x) {                                                           \\
    for (auto b : a)                                                           \\
      cerr << b << " ";                                                        \\
    cerr << en;                                                                \\
  }
#define getMat(x, n, m, val) vector<vector<int>> x(n, vector<int>(m, val))
#define fastio                                                                 \\
  ios_base ::sync_with_stdio(false);                                           \\
  cin.tie(nullptr);                                                            \\
  cout.tie(nullptr);
#define pout cout << fixed << setprecision(10)
int fastpow(int a, int b, int m = HELL) {
  int res = 1;
  a %= m;
  while (b > 0) {
    if (b & 1)
      res = (res * a) % m;
    a = (a * a) % m;
    b >>= 1;
  }
  return res;
}
#define inv(a) fastpow(a, HELL - 2)
#define mul(a, b) ((a % HELL) * (b % HELL)) % HELL

int n;
const int maxN = 2e5 + 5;
int tree[maxN];

void update(int index, int val) {
  while (index <= n) {
    tree[index] = (tree[index] + val) % HELL;
    index += (index & -index);
  }
}

int read(int index) {
  int sum = 0;
  while (index) {
    sum = (sum + tree[index]) % HELL;
    index -= (index & -index);
  }
  return sum;
}

int getSum(int low, int high) {
  if (high <= 0) {
    return 0;
  }
  if (low <= 1) {
    return read(high);
  }
  return (read(high) - read(low - 1) + HELL) % HELL;
}

int32_t main() {
  fastio;
  int k, a, b;
  cin >> n >> k;
  vector<vector<int>> s;
  while (k--) {
    cin >> a >> b;
    s.pb({a, b});
  }
  update(1, 1);
  for (int i = 2; i <= n; i++) {
    for (auto x : s) {
      update(i, getSum(i - x[1], i - x[0]));
    }
  }
  cout << (read(n) - read(n - 1) + HELL) % HELL << endl;
  return 0;
}


#define LOCAL
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = (n - 1); i >= 0; --i)
#define rep2(i, s, n) for (int i = s; i < (n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define memr(dp, val) memset(dp, val, sizeof(dp))
using namespace std;
typedef long long ll;
static const int INTINF = (INT_MAX >> 1); // 10^9 + 10^7
static const ll LLINF = (LLONG_MAX >> 1);
static const int MAX = 201001;
static const ll MOD = 998244353;
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 <class T> inline T int_ceil(T a, T b) {
  T res = a / b;
  if (a % b != 0)
    res++;
  return res;
}
template <typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
string to_string(string s) { return '"' + s + '"'; }
string to_string(bool b) { return b ? "true" : "false"; }
template <size_t N> string to_string(bitset<N> bs) {
  string res;
  for (size_t i = 0; i < N; ++i)
    res += '0' + bs[i];
  return res;
}
string to_string(vector<bool> v) {
  string res = "{";
  for (bool e : v)
    res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p);
template <class C> string to_string(C c) {
  string res = "{";
  for (auto e : c)
    res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
void debug() { cerr << '\\n'; }
template <class Head, class... Tail> void debug(Head head, Tail... tail) {
  cerr << '\\t' << to_string(head), debug(tail...);
}
#ifdef LOCAL
#define print(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__)
#else
#define print(...)
#endif

ll dp[MAX];
ll dp_minus[MAX];

int main(int argc, const char *argv[]) {
  std::cout << std::fixed << std::setprecision(15);

  memr(dp, 0);

  dp[0] = 1;
  dp_minus[1] = 1;
  int N, K;
  cin >> N >> K;
  vector<pair<int, int>> lr(K);
  rep(i, K) {
    int l, r;
    cin >> l >> r;
    lr[i] = {l, r};
  }

  rep(i, N) {
    // rep(i, N){
    // 	if(i) cout << " ";
    // 	cout << dp[i];
    // }
    // cout << endl;
    rep(j, K) {
      dp[i + lr[j].first] = (dp[i + lr[j].first] + dp[i]) % MOD;
      dp_minus[i + lr[j].second + 1] =
          (dp_minus[i + lr[j].second + 1] + dp[i]) % MOD;
    }
    dp[i + 1] = (dp[i] + dp[i + 1]) % MOD;
    dp[i + 1] = (dp[i + 1] - dp_minus[i + 1]) % MOD;
    while (dp[i + 1] < 0)
      dp[i + 1] += MOD;
  }
  // rep(i, N){
  // 	if(i) cout << " ";
  // 	cout << dp[i];
  // }
  // cout << endl;

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

  return 0;
}

#define LOCAL
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = (n - 1); i >= 0; --i)
#define rep2(i, s, n) for (int i = s; i < (n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define memr(dp, val) memset(dp, val, sizeof(dp))
using namespace std;
typedef long long ll;
static const int INTINF = (INT_MAX >> 1); // 10^9 + 10^7
static const ll LLINF = (LLONG_MAX >> 1);
static const int MAX = 201001;
static const ll MOD = 998244353;
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 <class T> inline T int_ceil(T a, T b) {
  T res = a / b;
  if (a % b != 0)
    res++;
  return res;
}
template <typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
string to_string(string s) { return '"' + s + '"'; }
string to_string(bool b) { return b ? "true" : "false"; }
template <size_t N> string to_string(bitset<N> bs) {
  string res;
  for (size_t i = 0; i < N; ++i)
    res += '0' + bs[i];
  return res;
}
string to_string(vector<bool> v) {
  string res = "{";
  for (bool e : v)
    res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p);
template <class C> string to_string(C c) {
  string res = "{";
  for (auto e : c)
    res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
void debug() { cerr << '\\n'; }
template <class Head, class... Tail> void debug(Head head, Tail... tail) {
  cerr << '\\t' << to_string(head), debug(tail...);
}
#ifdef LOCAL
#define print(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__)
#else
#define print(...)
#endif

ll dp[MAX];
ll dp_minus[MAX];

int main(int argc, const char *argv[]) {
  std::cout << std::fixed << std::setprecision(15);

  memr(dp, 0);

  dp[0] = 1;
  dp_minus[1] = 1;
  int N, K;
  cin >> N >> K;
  vector<pair<int, int>> lr(K);
  rep(i, K) {
    int l, r;
    cin >> l >> r;
    lr[i] = {l, r};
  }

  rep(i, N) {
    // rep(i, N){
    // 	if(i) cout << " ";
    // 	cout << dp[i];
    // }
    // cout << endl;
    rep(j, K) {
      if (i + lr[j].first >= MAX)
        continue;
      dp[i + lr[j].first] = (dp[i + lr[j].first] + dp[i]) % MOD;
      dp_minus[i + lr[j].second + 1] =
          (dp_minus[i + lr[j].second + 1] + dp[i]) % MOD;
    }
    dp[i + 1] = (dp[i] + dp[i + 1]) % MOD;
    dp[i + 1] = (dp[i + 1] - dp_minus[i + 1]) % MOD;
    while (dp[i + 1] < 0)
      dp[i + 1] += MOD;
  }
  // rep(i, N){
  // 	if(i) cout << " ";
  // 	cout << dp[i];
  // }
  // cout << endl;

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

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;
ll MOD = 998244353;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> l(k);
  vector<int> r(k);
  for (int i = 0; i < k; i++) {
    cin >> l[i] >> r[i];
  }
  vector<ll> dp(n + 5, 0);
  dp[1] = 1;
  for (int i = 1; i < n + 5; i++) {
    for (int j = 0; j < k; j++) {
      for (int s = l[j]; s <= min(r[j], n - i); s++) {
        dp[i + s] = (dp[i + s] + dp[i]) % MOD;
      }
    }
  }
  cout << dp[n] << endl;
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;
ll MOD = 998244353;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> l(k);
  vector<int> r(k);
  for (int i = 0; i < k; i++) {
    cin >> l[i] >> r[i];
  }
  vector<ll> dp(n + 5, 0);
  dp[1] = 1;
  vector<ll> chart(n + 5, 0);
  chart[1] = 1;
  for (int i = 2; i < n + 5; i++) {
    for (int j = 0; j < k; j++) {
      if (i - l[j] > 0) {
        ll left = max(1, min(i - r[j], i - 1)), right = i - l[j];
        dp[i] = max(dp[i], dp[i] + chart[right] - chart[left - 1]) % MOD;
      }
    }
    chart[i] = chart[i - 1] + dp[i];
  }
  cout << dp[n] << endl;
  return 0;
}


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

using namespace std;
using ll = long long;
using P = pair<int, int>;

template <class T1, class T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &v) {
  os << "(" << v.first << ", " << v.second << ")";
  return os;
}

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

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

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

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < k; j++) {
      for (int s = l[j]; s <= r[j]; s++) {
        if (i + s >= n)
          continue;
        f[i + s] += f[i];
        f[i + s] %= 998244353;
      }
    }
  }
  cout << f[n - 1] << endl;
  return 0;
}

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

using namespace std;
using ll = long long;
using P = pair<int, int>;

template <class T1, class T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &v) {
  os << "(" << v.first << ", " << v.second << ")";
  return os;
}

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

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

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

  for (int i = 1; i < n; i++) {
    for (int j = 0; j < k; j++) {
      dp[i] += acc[max(0, i - l[j] + 1)] - acc[max(0, i - r[j])];
      dp[i] = (dp[i] + mod) % mod;
      acc[i + 1] = acc[i] + dp[i];
      acc[i + 1] %= mod;
    }
  }
  cout << dp[n - 1] << endl;
  return 0;
}


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

int N, K;
int L[15], R[15];
long long imos[202020];
long long now = 1;

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

  for (int i = 1; i <= N; i++) {
    now += imos[i];
    now %= 998244353LL;
    for (int j = 0; j < K; j++) {
      if (i + L[j] < 202020) {
        imos[i + L[j]] += now;
      }
      if (i + R[j] < 202020) {
        imos[i + R[j] + 1] -= now;
      }
    }
    if (i == N) {
      while (imos[N] < 0LL) {
        imos[N] += 998244353LL;
      }
      cout << imos[N] % 998244353LL << endl;
    }
  }
}

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

int N, K;
int L[15], R[15];
long long imos[202020];
long long now = 1;

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

  for (int i = 1; i <= N; i++) {
    now += imos[i];
    now %= 998244353LL;
    for (int j = 0; j < K; j++) {
      if (i + L[j] < 202020) {
        imos[i + L[j]] += now;
      }
      if (i + R[j] + 1 < 202020) {
        imos[i + R[j] + 1] -= now;
      }
    }
    if (i == N) {
      while (imos[N] < 0LL) {
        imos[N] += 998244353LL;
      }
      cout << imos[N] % 998244353LL << endl;
    }
  }
}


#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<ll, ll>> vpll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vc> vvc;
typedef vector<vs> vvs;
typedef vector<vll> vvll;
typedef map<int, int> mii;
typedef set<int> si;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define arep(i, v) for (auto i : v)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define fi first
#define se second
// #include <atcoder/all>
// using namespace atcoder;
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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 <class T> inline void dump(T &v) {
  irep(i, v) { cout << (*i) << ((i == --v.end()) ? '\\n' : ' '); }
}
template <class T, class U> inline void dump(map<T, U> &v) {
  irep(i, v) { cout << i->first << " " << i->second << '\\n'; }
}
inline string getline() {
  string s;
  getline(cin, s);
  return s;
}
inline void yn(const bool b) { b ? fin("yes") : fin("no"); }
inline void Yn(const bool b) { b ? fin("Yes") : fin("No"); }
inline void YN(const bool b) { b ? fin("YES") : fin("NO"); }
struct io {
  io() {
    ios::sync_with_stdio(false);
    cin.tie(0);
  }
};
const int INF = INT_MAX;
constexpr ll LLINF = 1LL << 61;
constexpr ll MOD = 998244353; // 1000000007;
constexpr ld EPS = 1e-11;

/* --------------------   ここまでテンプレ   -------------------- */

struct mint {
  ll x;
  mint(ll _x = 0) : x((_x % MOD + MOD) % MOD) {}

  /* 初期化子 */
  mint operator+() const { return mint(x); }
  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) {
    x *= modinv(a).x;
    x %= MOD;
    return (*this);
  }
  mint &operator%=(const mint a) {
    x %= a.x;
    return (*this);
  }
  mint &operator++() {
    ++x;
    if (x >= MOD)
      x -= MOD;
    return *this;
  }
  mint &operator--() {
    if (!x)
      x += MOD;
    --x;
    return *this;
  }
  mint &operator&=(const mint a) {
    x &= a.x;
    return (*this);
  }
  mint &operator|=(const mint a) {
    x |= a.x;
    return (*this);
  }
  mint &operator^=(const mint a) {
    x ^= a.x;
    return (*this);
  }
  mint &operator<<=(const mint a) {
    x *= pow(2, a).x;
    return (*this);
  }
  mint &operator>>=(const mint a) {
    x /= pow(2, a).x;
    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 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 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 operator>>(const mint a) const {
    mint res(*this);
    return res >>= a;
  }

  /* 条件演算子 */
  bool operator==(const mint a) const noexcept { return x == a.x; }
  bool operator!=(const mint a) const noexcept { return x != a.x; }
  bool operator<(const mint a) const noexcept { return x < a.x; }
  bool operator>(const mint a) const noexcept { return x > a.x; }
  bool operator<=(const mint a) const noexcept { return x <= a.x; }
  bool operator>=(const mint a) const noexcept { return x >= a.x; }

  /* ストリーム挿入演算子 */
  friend istream &operator>>(istream &is, mint &m) {
    is >> m.x;
    m.x = (m.x % MOD + MOD) % MOD;
    return is;
  }
  friend ostream &operator<<(ostream &os, const mint &m) {
    os << m.x;
    return os;
  }

  /* その他の関数 */
  mint modinv(mint a) { return pow(a, MOD - 2); }
  mint pow(mint x, mint n) {
    mint res = 1;
    while (n.x > 0) {
      if ((n % 2).x)
        res *= x;
      x *= x;
      n.x /= 2;
    }
    return res;
  }
};

template <typename T> class Sum {
public:
  // 単位元
  T unit;

  Sum(void) {
    // 単位元
    unit = 0;
  }

  // 演算関数
  T calc(T a, T b) { return a + b; }
};

template <typename T> struct Min {
public:
  // 単位元
  T unit;

  Min(void) {
    // 単位元
    unit = INF;
  }

  // 演算関数
  T calc(T a, T b) { return min(a, b); }
};

template <typename T, class MONOID> class SegmentTree {
public:
  // セグメント木の葉の要素数
  int n;

  // セグメント木
  vector<T> tree;

  // モノイド
  MONOID mono;

  SegmentTree(vector<T> &v)
      : n(1 << (int)ceil(log2(v.size()))), tree(vector<T>(n << 1)) {
    for (int i = 0; i < v.size(); ++i) {
      update(i, v[i]);
    }
    for (int i = v.size(); i < n; ++i) {
      update(i, mono.unit);
    }
  }

  // k番目の値(0-indexed)をxに変更
  void update(int k, T x) {
    k += n;
    tree[k] = x;
    for (k = k >> 1; k > 0; k >>= 1) {
      tree[k] = mono.calc(tree[k << 1 | 0], tree[k << 1 | 1]);
    }
  }

  // [l, r)の最小値(0-indexed)を求める．
  T query(int l, int r) {
    T res = mono.unit;
    l += n;
    r += n;
    while (l < r) {
      if (l & 1) {
        res = mono.calc(res, tree[l++]);
      }
      if (r & 1) {
        res = mono.calc(res, tree[--r]);
      }
      l >>= 1;
      r >>= 1;
    }
    return res;
  }

  T operator[](int k) {
    // st[i]で添字iの要素の値を返す
    if (k - n >= 0 || k < 0) {
      return -INF;
    }
    return tree[tree.size() - n + k];
  }

  void show(void) {
    int ret = 2;
    for (int i = 1; i < 2 * n; ++i) {
      if (tree[i] == mono.unit)
        cout << "UNIT ";
      else
        cout << tree[i] << " ";
      if (i == ret - 1) {
        cout << endl;
        ret <<= 1;
      }
    }
    cout << endl;
  }
};

int main() {
  int n, k;
  cin >> n >> k;
  vector<pair<int, int>> r(k);
  rep(i, k) { cin >> r[i].fi >> r[i].se; }
  // セグメント木の作成
  vector<mint> v(n + 10, 0);
  SegmentTree<mint, Sum<mint>> st(v);

  {
    // dp[1] = 1;
    st.update(0, st[0] + 1);
    st.update(1, st[1] - 1);
  }
  // st.show();
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < k; j++) {
      int s = r[j].first + i;
      int t = r[j].second + i;
      mint x = st.query(0, i + 1);
      st.update(s, st[s] + x);
      st.update(t + 1, st[t + 1] - x);
    }
    // st.show();
  }
  cout << st.query(0, n).x << endl;
  /*
      int n, q;
      int query, s, t, x, i;
      cin >> n >> q;

      while (q--) {
          scanf("%d", &query);
          if (query) {
              // クエリget(i)の時
              scanf("%d", &i);
              printf("%d\\n", st.query(0, i));
          } else {
              // クエリadd(s, t, x)の時
              scanf("%d %d %d", &s, &t, &x);
              // 私のセグメント木の更新処理は加算ではなく代入なので，
              // これはs - 1番目の値をx足しているのと同義です．
              st.update(s - 1, st[s - 1] + x);
              st.update(t, st[t] - x);
          }
      }*/
}

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<ll, ll>> vpll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vc> vvc;
typedef vector<vs> vvs;
typedef vector<vll> vvll;
typedef map<int, int> mii;
typedef set<int> si;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define arep(i, v) for (auto i : v)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define fi first
#define se second
// #include <atcoder/all>
// using namespace atcoder;
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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 <class T> inline void dump(T &v) {
  irep(i, v) { cout << (*i) << ((i == --v.end()) ? '\\n' : ' '); }
}
template <class T, class U> inline void dump(map<T, U> &v) {
  irep(i, v) { cout << i->first << " " << i->second << '\\n'; }
}
inline string getline() {
  string s;
  getline(cin, s);
  return s;
}
inline void yn(const bool b) { b ? fin("yes") : fin("no"); }
inline void Yn(const bool b) { b ? fin("Yes") : fin("No"); }
inline void YN(const bool b) { b ? fin("YES") : fin("NO"); }
struct io {
  io() {
    ios::sync_with_stdio(false);
    cin.tie(0);
  }
};
const int INF = INT_MAX;
constexpr ll LLINF = 1LL << 61;
constexpr ll MOD = 998244353; // 1000000007;
constexpr ld EPS = 1e-11;

/* --------------------   ここまでテンプレ   -------------------- */

struct mint {
  ll x;
  mint(ll _x = 0) : x((_x % MOD + MOD) % MOD) {}

  /* 初期化子 */
  mint operator+() const { return mint(x); }
  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) {
    x *= modinv(a).x;
    x %= MOD;
    return (*this);
  }
  mint &operator%=(const mint a) {
    x %= a.x;
    return (*this);
  }
  mint &operator++() {
    ++x;
    if (x >= MOD)
      x -= MOD;
    return *this;
  }
  mint &operator--() {
    if (!x)
      x += MOD;
    --x;
    return *this;
  }
  mint &operator&=(const mint a) {
    x &= a.x;
    return (*this);
  }
  mint &operator|=(const mint a) {
    x |= a.x;
    return (*this);
  }
  mint &operator^=(const mint a) {
    x ^= a.x;
    return (*this);
  }
  mint &operator<<=(const mint a) {
    x *= pow(2, a).x;
    return (*this);
  }
  mint &operator>>=(const mint a) {
    x /= pow(2, a).x;
    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 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 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 operator>>(const mint a) const {
    mint res(*this);
    return res >>= a;
  }

  /* 条件演算子 */
  bool operator==(const mint a) const noexcept { return x == a.x; }
  bool operator!=(const mint a) const noexcept { return x != a.x; }
  bool operator<(const mint a) const noexcept { return x < a.x; }
  bool operator>(const mint a) const noexcept { return x > a.x; }
  bool operator<=(const mint a) const noexcept { return x <= a.x; }
  bool operator>=(const mint a) const noexcept { return x >= a.x; }

  /* ストリーム挿入演算子 */
  friend istream &operator>>(istream &is, mint &m) {
    is >> m.x;
    m.x = (m.x % MOD + MOD) % MOD;
    return is;
  }
  friend ostream &operator<<(ostream &os, const mint &m) {
    os << m.x;
    return os;
  }

  /* その他の関数 */
  mint modinv(mint a) { return pow(a, MOD - 2); }
  mint pow(mint x, mint n) {
    mint res = 1;
    while (n.x > 0) {
      if ((n % 2).x)
        res *= x;
      x *= x;
      n.x /= 2;
    }
    return res;
  }
};

template <typename T> class Sum {
public:
  // 単位元
  T unit;

  Sum(void) {
    // 単位元
    unit = 0;
  }

  // 演算関数
  T calc(T a, T b) { return a + b; }
};

template <typename T> struct Min {
public:
  // 単位元
  T unit;

  Min(void) {
    // 単位元
    unit = INF;
  }

  // 演算関数
  T calc(T a, T b) { return min(a, b); }
};

template <typename T, class MONOID> class SegmentTree {
public:
  // セグメント木の葉の要素数
  int n;

  // セグメント木
  vector<T> tree;

  // モノイド
  MONOID mono;

  SegmentTree(vector<T> &v)
      : n(1 << (int)ceil(log2(v.size()))), tree(vector<T>(n << 1)) {
    for (int i = 0; i < v.size(); ++i) {
      update(i, v[i]);
    }
    for (int i = v.size(); i < n; ++i) {
      update(i, mono.unit);
    }
  }

  // k番目の値(0-indexed)をxに変更
  void update(int k, T x) {
    k += n;
    tree[k] = x;
    for (k = k >> 1; k > 0; k >>= 1) {
      tree[k] = mono.calc(tree[k << 1 | 0], tree[k << 1 | 1]);
    }
  }

  // [l, r)の最小値(0-indexed)を求める．
  T query(int l, int r) {
    T res = mono.unit;
    l += n;
    r += n;
    while (l < r) {
      if (l & 1) {
        res = mono.calc(res, tree[l++]);
      }
      if (r & 1) {
        res = mono.calc(res, tree[--r]);
      }
      l >>= 1;
      r >>= 1;
    }
    return res;
  }

  T operator[](int k) {
    // st[i]で添字iの要素の値を返す
    if (k - n >= 0 || k < 0) {
      return -INF;
    }
    return tree[tree.size() - n + k];
  }

  void show(void) {
    int ret = 2;
    for (int i = 1; i < 2 * n; ++i) {
      if (tree[i] == mono.unit)
        cout << "UNIT ";
      else
        cout << tree[i] << " ";
      if (i == ret - 1) {
        cout << endl;
        ret <<= 1;
      }
    }
    cout << endl;
  }
};

int main() {
  int n, k;
  cin >> n >> k;
  vector<pair<int, int>> r(k);
  rep(i, k) { cin >> r[i].fi >> r[i].se; }
  // セグメント木の作成
  vector<mint> v(n + 10, 0);
  SegmentTree<mint, Sum<mint>> st(v);

  {
    // dp[1] = 1;
    st.update(0, st[0] + 1);
    st.update(1, st[1] - 1);
  }
  // st.show();
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < k; j++) {
      int s = r[j].first + i;
      int t = r[j].second + i;
      chmin(s, n + 5);
      chmin(t, n + 5);
      mint x = st.query(0, i + 1);
      st.update(s, st[s] + x);
      st.update(t + 1, st[t + 1] - x);
    }
    // st.show();
  }
  cout << st.query(0, n).x << endl;
  /*
      int n, q;
      int query, s, t, x, i;
      cin >> n >> q;

      while (q--) {
          scanf("%d", &query);
          if (query) {
              // クエリget(i)の時
              scanf("%d", &i);
              printf("%d\\n", st.query(0, i));
          } else {
              // クエリadd(s, t, x)の時
              scanf("%d %d %d", &s, &t, &x);
              // 私のセグメント木の更新処理は加算ではなく代入なので，
              // これはs - 1番目の値をx足しているのと同義です．
              st.update(s - 1, st[s - 1] + x);
              st.update(t, st[t] - x);
          }
      }*/
}


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

#define V vector
typedef long long ll;
typedef unsigned long long ull;

typedef V<int> vi;
typedef V<ll> vll;
typedef V<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define f(i, a) for (int i = 0; i < a; i++)
#define fll(i, a) for (ll i = 0; i < a; i++)
#define forab(i, a, b) for (int i = a; i < b; i++)
#define prec(x) cout << fixed << setprecision(x)
#define ff first
#define ss second

#define pb push_back
#define mp make_pair
#define numberofdigits(x) floor(log10(x)) + 1
#define all(x) (x).begin(), (x).end()

const ll mod = 998244353;

ll binpow(ll a, long long b) {
  ll res = 1;
  while (b > 0) {
    if (b & 1)
      res = (res * a);
    a = (a * a);
    b >>= 1;
  }
  return res;
}
const int N = 1e6 + 5;

void solve() {

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

  vector<int> a;

  for (int i = 0; i < k; i++) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++)
      a.pb(j);
  }

  ll dp[n + 1];
  memset(dp, 0, sizeof(dp));
  int sz = a.size();
  dp[0] = 1, dp[1] = 1;

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

      if (i - a[j] >= 1)
        dp[i] = (dp[i] % mod + dp[i - a[j]] % mod) % mod;
    }
  }

  cout << dp[n] << "\\n";
}

int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  int t = 1;
  // cin >> t;

  while (t--)
    solve();
  return 0;
}

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

#define V vector
typedef long long ll;
typedef unsigned long long ull;

typedef V<int> vi;
typedef V<ll> vll;
typedef V<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define f(i, a) for (int i = 0; i < a; i++)
#define fll(i, a) for (ll i = 0; i < a; i++)
#define forab(i, a, b) for (int i = a; i < b; i++)
#define prec(x) cout << fixed << setprecision(x)
#define ff first
#define ss second

#define pb push_back
#define mp make_pair
#define numberofdigits(x) floor(log10(x)) + 1
#define all(x) (x).begin(), (x).end()

const ll mod = 998244353;

ll binpow(ll a, long long b) {
  ll res = 1;
  while (b > 0) {
    if (b & 1)
      res = (res * a);
    a = (a * a);
    b >>= 1;
  }
  return res;
}
const int N = 1e6 + 5;

void solve() {

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

  int dp[n + 5], pref[n + 5];
  memset(dp, 0, sizeof(dp));
  memset(pref, 0, sizeof(pref));
  dp[1] = 1, pref[1] = 1;

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

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

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

      if (i <= l[j])
        continue;
      int L = l[j];
      int R = min(r[j], i - 1);

      dp[i] =
          (dp[i] % mod + ((pref[i - L] - pref[i - R - 1]) % mod + mod) % mod) %
          mod;
    }

    pref[i] = (pref[i - 1] % mod + dp[i] % mod) % mod;
  }

  cout << dp[n] << "\\n";
}

int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  int t = 1;
  // cin >> t;

  while (t--)
    solve();
  return 0;
}


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

int dp[300000];

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

  vector<int> dist;
  rep(i, k) {
    int l, r;
    cin >> l >> r;
    for (int i = l; i <= r; i++) {
      dist.push_back(i);
    }
  }

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

  dp[0] = 1;
  rep(i, n) {
    if (i + dist[0] > n)
      break;
    for (int d : dist) {
      if (i + d > n)
        break;
      dp[i + d] = (dp[i + d] + dp[i]) % MOD;
    }
  }

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

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

int dp[300000];

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

  vector<pair<int, int>> lr;
  rep(i, k) {
    int l, r;
    cin >> l >> r;
    lr.push_back({l, r + 1});
  }

  dp[0] = 1;
  dp[1] = -1;
  rep(i, n) {
    if (i > 0)
      dp[i] = (dp[i] + dp[i - 1]) % MOD;
    rep(j, k) {
      int l, r;
      tie(l, r) = lr[j];
      if (i + l < n)
        dp[i + l] = (dp[i + l] + dp[i]) % MOD;
      if (i + r < n)
        dp[i + r] = (dp[i + r] - dp[i] + MOD) % MOD;
    }
  }

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


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

#define int long long int
#define ff first
#define ss second
#define pb push_back
#define fastio                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);

const int mod = 1e9 + 7;
const int cmod = 998244353;
const int N = 3e5 + 5;
const int inf = 1e18 + 2;

void solve(int Case) {
  int n, k;
  cin >> n >> k;
  set<int> s;
  while (k--) {
    int a, b;
    cin >> a >> b;
    for (int i = a; i <= b; i++)
      s.insert(i);
  }
  vector<pair<int, int>> seg;
  int prev = -1, l = 0, r = 0;
  for (auto x : s) {
    if (prev == -1) {
      l = r = x;
      prev = x;
      continue;
    }
    if (x == prev + 1)
      r++;
    else {
      seg.push_back({l, r});
      prev = x;
      l = r = x;
    }
  }
  if (l != 0)
    seg.push_back({l, r});
  // for(auto X : seg) cout << X.ff << ' ' << X.ss << '\\n';
  int ad[n + 10], dp[n + 10];
  memset(ad, 0, sizeof ad);
  memset(dp, 0, sizeof dp);
  dp[1] = 1;
  for (int i = 1; i <= n; i++) {
    ad[i] = (ad[i] + ad[i - 1]) % cmod;
    dp[i] = (dp[i] + ad[i] + cmod) % cmod;
    for (int j = 0; j < seg.size(); j++) {
      if (i + seg[j].ff > n)
        continue;
      ad[i + seg[j].ff] = (ad[i + seg[j].ff] + dp[i]) % cmod;
      int temp = min(i + seg[j].ss, n);
      ad[temp + 1] = (ad[temp + 1] - dp[i] + cmod) % cmod;
    }
  }

  cout << dp[n] << '\\n';
}
/*
 */

int32_t main() {
  fastio int testcase = 1;
  // cin >> testcase;
  int Case = 1;
  while (testcase--) {
    solve(Case);
  }
  return 0;
}

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

#define int long long int
#define ff first
#define ss second
#define pb push_back
#define fastio                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);

const int mod = 1e9 + 7;
const int cmod = 998244353;
const int N = 3e5 + 5;
const int inf = 1e18 + 2;

void solve(int Case) {
  int n, k;
  cin >> n >> k;
  // set<int> s ;
  vector<pair<int, int>> seg;
  while (k--) {
    int a, b;
    cin >> a >> b;
    seg.push_back({a, b});
  }

  // for(auto X : seg) cout << X.ff << ' ' << X.ss << '\\n';
  int ad[n + 2], dp[n + 2];
  memset(ad, 0, sizeof ad);
  memset(dp, 0, sizeof dp);
  dp[1] = 1;
  for (int i = 1; i <= n; i++) {
    ad[i] = (ad[i] + ad[i - 1] + cmod) % cmod;
    dp[i] = (dp[i] + ad[i] + cmod) % cmod;
    for (int j = 0; j < seg.size(); j++) {
      if (i + seg[j].ff > n)
        continue;
      ad[i + seg[j].ff] = (ad[i + seg[j].ff] + dp[i] + cmod) % cmod;
      int temp = min(i + seg[j].ss, n);
      ad[temp + 1] = (ad[temp + 1] - dp[i] + cmod) % cmod;
    }
  }

  cout << dp[n] << '\\n';
}
/*
 */

int32_t main() {
  fastio int testcase = 1;
  // cin >> testcase;
  int Case = 1;
  while (testcase--) {
    solve(Case);
  }
  return 0;
}


#include <bits/stdc++.h>
#define ll long long

using namespace std;

struct Node {
  int data;
  struct Node *left;
  struct Node *right;
  Node(int x) {
    data = x;
    left = NULL;
    right = NULL;
  }
};
#define Node struct Node

ll modpow(ll a, ll n) {
  ll m = 1e9 + 7;
  if (n == 0)
    return 1;
  ll y = modpow(a, n / 2) % m;
  if (n % 2 == 0)
    return (y * y) % m;
  return (((y * y) % m) * a) % m;
}

ll dp[200005];
ll pro(int i, vector<int> &v) {
  if (i == 1)
    return 1;
  if (i <= 0)
    return 0;
  if (dp[i] != -1)
    return dp[i];
  ll m = 998244353;
  ll ans = 0;
  for (int j = 0; j < v.size(); j++) {
    if (v[j] >= i)
      break;
    ans += pro(i - v[j], v);
    ans = ans % m;
  }
  return dp[i] = ans;
}

int main() {
  int t = 1;
  // cin>>t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    vector<int> v;
    for (int i = 0; i < k; i++) {
      int x, y;
      cin >> x >> y;
      for (ll j = x; j <= y; j++)
        v.push_back(j);
    }
    sort(v.begin(), v.end());
    memset(dp, -1, sizeof(dp));
    cout << pro(n, v) << endl;
  }
  return 0;
}

#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> pll;
typedef vector<pair<ll, ll>> vpll;
#define kill                                                                   \\
  freopen("input.txt", "r", stdin);                                            \\
  freopen("output.txt", "w", stdout);
#define pb push_back
#define fo(i, n) for (ll i = 0; i < n; i++)
#define rev(i, n) for (ll i = n - 1; i >= 0; i--)
#define all(c) c.begin(), c.end()
#define go(c, it) for (auto it = (c).begin(); it != (c).end(); it++)
#define fi first
#define se second
#define MOD 998244353
#define Boost()                                                                \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL)
#define MOD1 1000000007
ll power(ll a, ll b) {
  ll res = 1;
  while (b > 0) {
    if (b & 1) {
      res = (res * a) % MOD;
    }
    a = (a * a) % MOD;
    b >>= 1LL;
  }
  return res;
}
ll fermat_inv(ll y) { return power(y, MOD - 2); }
ll gcd(ll a, ll b) { return (b == 0) ? a : gcd(b, a % b); }
#define oo LLONG_MAX
const ll dx[] = {-1, 0, 1, 0, -1, 1, 1, -1};
const ll dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

void solve() {
  ll n, k;
  cin >> n >> k;
  vl l(k), r(k);
  fo(i, k) { cin >> l[i] >> r[i]; }
  ll ans = 0;
  ll dp[n + 1] = {0};
  dp[1] = 1;
  dp[2] = -1;
  for (ll i = 1; i <= n; i++) {
    dp[i] = (dp[i] + dp[i - 1]) % MOD;
    fo(j, k) {
      ll left = l[j];
      ll right = r[j] + 1;
      if (i + left <= n)
        dp[i + left] = (dp[i + left] + dp[i]) % MOD;
      if (i + right <= n)
        dp[i + right] = (dp[i + right] - dp[i] + MOD) % MOD;
    }
  }
  cout << dp[n];
}

int main() {
  Boost();
  ll T = 1;
  // cin>>T;
  while (T--) {
    solve();
  }
  return 0;
}


#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// MACROS
#define _crt_secure_no_warnings
#define FREEELO                                                                \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define pb push_back
#define mp make_pair
#define INF 0x3F3F3F3F
#define MAX 200001
#define MOD 998244353
#define ALPHABET 128
#define loop(i, n) for (int i = 1; i <= (n); i++)
#define loop0(i, n) for (int i = 0; i < (n); i++)
#define sz(x) (int)x.size()
#define all(v) v.begin(), v.end()
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<ll, ll> llll;
typedef pair<int, int> ii;
typedef unordered_map<int, int> umii;
typedef unordered_map<ll, ll> umll;
typedef unordered_set<int> usi;
typedef unordered_multiset<int> usmi;
ll dp[MAX];
umii m;
int main() {
  FREEELO
  int n, k;
  cin >> n >> k;
  dp[1] = 1;
  vector<ii> steps(k + 1);
  loop(i, k) { cin >> steps[i].F >> steps[i].S; }
  if (n == 1) {
    cout << 0;
    return 0;
  }
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < sz(steps); j++) {
      for (int k = steps[j].F; k <= steps[j].S; k++) {
        if (i - k < 0)
          break;
        dp[i] = (dp[i] + dp[i - k]) % MOD;
      }
    }
  }
  cout << dp[n] << endl;
}

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// MACROS
#define _crt_secure_no_warnings
#define FREEELO                                                                \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define pb push_back
#define mp make_pair
#define INF 0x3F3F3F3F3F3F3F3FLL
#define MAX 200001
#define MOD 998244353
#define ALPHABET 128
#define loop(i, n) for (int i = 1; i <= (n); i++)
#define loop0(i, n) for (int i = 0; i < (n); i++)
#define sz(x) (int)x.size()
#define all(v) v.begin(), v.end()
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<ll, ll> llll;
typedef pair<int, int> ii;
typedef unordered_map<int, int> umii;
typedef unordered_map<ll, ll> umll;
typedef unordered_set<int> usi;
typedef unordered_multiset<int> usmi;
struct node {
  ll sum, add;
  node() { add = 0; }
} st[4 * MAX];
ll dp[MAX];
void Build(ll v, ll l, ll r) {
  if (l == r) {
    st[v].sum = dp[l];
    st[v].add = 0;
    return;
  }
  ll mid = (l + r) / 2;
  Build(2 * v, l, mid);
  Build(2 * v + 1, mid + 1, r);
  st[v].sum = st[2 * v].sum + st[2 * v + 1].sum;
  st[v].add = 0;
}

void Push(ll v, ll l, ll mid, ll r) {
  if (st[v].add != 0) {
    st[2 * v].add += st[v].add % MOD;
    st[2 * v + 1].add += st[v].add % MOD;
    st[2 * v].sum += ((mid - l + 1) * st[v].add) % MOD;
    st[2 * v + 1].sum += ((r - mid) * st[v].add) % MOD;
    st[v].add = 0;
  }
}

void Update(ll v, ll l, ll r, ll i, ll j, ll d) {
  if (i > j)
    return;
  if (l == i && r == j) {
    st[v].add = (st[v].add + d) % MOD;
    st[v].sum = (st[v].sum + 1LL * (j - i + 1) * d % MOD) % MOD;
    return;
  }
  ll mid = (l + r) / 2;
  Push(v, l, mid, r);
  Update(2 * v, l, mid, i, min(mid, j), d);
  Update(2 * v + 1, mid + 1, r, max(mid + 1, i), j, d);
  st[v].sum = (st[2 * v].sum % MOD + st[2 * v + 1].sum % MOD) % MOD;
}

ll Sum(ll v, ll l, ll r, ll i, ll j) {
  if (i > j)
    return 0;
  if (l == i && r == j)
    return st[v].sum;
  ll mid = (l + r) / 2;
  Push(v, l, mid, r);
  return (Sum(2 * v, l, mid, i, min(mid, j)) % MOD +
          Sum(2 * v + 1, mid + 1, r, max(i, mid + 1), j) % MOD) %
         MOD;
}

umii m;
int main() {
  FREEELO
  int n, k;
  cin >> n >> k;
  dp[1] = 1;
  vector<ii> steps(k + 1);
  loop(i, k) { cin >> steps[i].F >> steps[i].S; }
  if (n == 1) {
    cout << 0;
    return 0;
  }
  Build(1, 1, n);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j < sz(steps); j++) {
      int k1 = i + steps[j].F;
      if (k1 > n)
        continue;
      int k2 = i + steps[j].S;
      if (k2 > n)
        k2 = n;
      Update(1, 1, n, k1, k2, Sum(1, 1, n, i, i));
    }
  }
  cout << Sum(1, 1, n, n, n) << endl;
}


#include <bits/stdc++.h>
#define ll long long int
#define mod 998244353
#define pi 3.14159265358979323846264338327950288419716939937510
#define setbit(x) __builtin_popcountll(x)
#define db long double
#define pp(x) pair<x, x>
#define ff first
#define ss second
#define FIO                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
#define tc                                                                     \\
  ll tc;                                                                       \\
  cin >> tc;                                                                   \\
  for (ll number = 1; number <= tc; number++)
#define vv(x) vector<x>
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define endl "\\n"
#define pq priority_queue
#define dbg(x)                                                                 \\
  { cout << #x << ": " << (x) << endl; }
#define dbg2(x, y)                                                             \\
  { cout << #x << ": " << (x) << " , " << #y << ": " << (y) << endl; }
#define bp                                                                     \\
  ll kkk;                                                                      \\
  cin >> kkk;
#define dbgArr(a, n)                                                           \\
  cout << "Array " << #a << endl;                                              \\
  for (ll i = 0; i < n; i++)                                                   \\
    cout << a[i] << " ";                                                       \\
  cout << endl;
#define maxE(a, n) *max_element(a, a + n);
#define minE(a, n) *min_element(a, a + n);
#define forn(i, s, n) for (ll i = s; i < n; i++)
#define fornr(i, e, s) for (ll i = e - 1; i >= s; i--)
#define arr1(a, n)                                                             \\
  for (ll i = 1; i <= n; i++) {                                                \\
    cin >> a[i];                                                               \\
  }
#define file                                                                   \\
  freopen("input.txt", "r", stdin);                                            \\
  freopen("output.txt", "w", stdout)
#define print cout << "Case #" << number << ": "
#define all(x) x.begin(), x.end()
ll power(ll x, ll b) {
  ll p = 1;
  while (b > 0) {
    if (b & 1) {
      p = p * x;
      p %= mod;
    }
    b >>= 1;
    x *= x;
    x %= mod;
  }
  return p % mod;
}
using namespace std;
#define INF 1e15

struct ppp {
  ll a, b, c;
};

struct lex_compare {
  bool operator()(ppp p1, ppp p2) {
    if (p1.a == p2.a) {
      if (p1.b == p2.b)
        return p1.c < p2.c;
      else
        return p1.b < p2.b;
    } else {
      return p1.a < p2.a;
    }
  }
};
ll dp[200004 + 1];

ll dfs(ll i, set<ll> &s, ll n) {
  if (i == n) {
    return 1;
  }
  if (dp[i] != -1)
    return dp[i];
  ll ans = 0;
  for (auto j : s) {
    if (i + j <= n) {
      ans += dfs(i + j, s, n);
      ans %= mod;
    } else {
      break;
    }
  }
  return dp[i] = ans;
}

int main() {
  FIO;
  ll n, k;
  cin >> n >> k;
  set<ll> s;
  forn(i, 0, k) {
    ll a, b;
    cin >> a >> b;
    forn(j, a, b + 1) s.insert(j);
  }
  ll ans = 0;

  memset(dp, -1, sizeof(dp));
  ans = dfs(1, s, n);
  cout << ans << endl;
  return 0;
}

#include <bits/stdc++.h>
#define ll long long int
#define mod 998244353
#define pi 3.14159265358979323846264338327950288419716939937510
#define setbit(x) __builtin_popcountll(x)
#define db long double
#define pp(x) pair<x, x>
#define ff first
#define ss second
#define FIO                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
#define tc                                                                     \\
  ll tc;                                                                       \\
  cin >> tc;                                                                   \\
  for (ll number = 1; number <= tc; number++)
#define vv(x) vector<x>
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define endl "\\n"
#define pq priority_queue
#define dbg(x)                                                                 \\
  { cout << #x << ": " << (x) << endl; }
#define dbg2(x, y)                                                             \\
  { cout << #x << ": " << (x) << " , " << #y << ": " << (y) << endl; }
#define bp                                                                     \\
  ll kkk;                                                                      \\
  cin >> kkk;
#define dbgArr(a, n)                                                           \\
  cout << "Array " << #a << endl;                                              \\
  for (ll i = 0; i < n; i++)                                                   \\
    cout << a[i] << " ";                                                       \\
  cout << endl;
#define maxE(a, n) *max_element(a, a + n);
#define minE(a, n) *min_element(a, a + n);
#define forn(i, s, n) for (ll i = s; i < n; i++)
#define fornr(i, e, s) for (ll i = e - 1; i >= s; i--)
#define arr1(a, n)                                                             \\
  for (ll i = 1; i <= n; i++) {                                                \\
    cin >> a[i];                                                               \\
  }
#define file                                                                   \\
  freopen("input.txt", "r", stdin);                                            \\
  freopen("output.txt", "w", stdout)
#define print cout << "Case #" << number << ": "
#define all(x) x.begin(), x.end()
ll power(ll x, ll b) {
  ll p = 1;
  while (b > 0) {
    if (b & 1) {
      p = p * x;
      p %= mod;
    }
    b >>= 1;
    x *= x;
    x %= mod;
  }
  return p % mod;
}
using namespace std;
#define INF 1e15

struct ppp {
  ll a, b, c;
};

struct lex_compare {
  bool operator()(ppp p1, ppp p2) {
    if (p1.a == p2.a) {
      if (p1.b == p2.b)
        return p1.c < p2.c;
      else
        return p1.b < p2.b;
    } else {
      return p1.a < p2.a;
    }
  }
};
ll dp[200004 + 1];

ll dfs(ll i, set<ll> &s, ll n) {
  if (i == n) {
    return 1;
  }
  if (dp[i] != -1)
    return dp[i];
  ll ans = 0;
  for (auto j : s) {
    if (i + j <= n) {
      ans += dfs(i + j, s, n);
      ans %= mod;
    } else {
      break;
    }
  }
  return dp[i] = ans;
}

int main() {
  FIO;
  ll n, k;
  cin >> n >> k;
  set<ll> s;
  pp(ll) arr[k];
  forn(i, 0, k) { cin >> arr[i].ff >> arr[i].ss; }
  sort(arr, arr + k);
  ll ans = 0;

  memset(dp, 0, sizeof(dp));
  dp[n] = 1;
  ll presum[n + 5] = {0};
  presum[n] = 1;
  for (int i = n - 1; i > 0; i--) {
    ll ind = i;
    ll temp = 0;
    for (int j = 0; j < k; j++) {
      if (ind + arr[j].ff <= n) {
        temp += (presum[ind + arr[j].ff] -
                 presum[min(n + 1, ind + arr[j].ss + 1)] + mod) %
                mod;
      } else {
        break;
      }
    }
    // dbg2(i,temp);
    presum[i] = (temp + presum[i + 1]) % mod;
  }
  // dbgArr(presum, n+3);
  cout << (presum[1] - presum[2] + mod) % mod << endl;
  return 0;
}


#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

const ll mod = 998244353;
int n;
vector<int> v;

int main() {
  cin >> n;
  int k;
  cin >> k;
  vector<int> dic(n + 1);
  rep(i, k) {
    int l, r;
    cin >> l >> r;
    dic[l]++;
    if (r + 1 <= n)
      dic[r + 1]--;
  }
  rep(i, n) { dic[i + 1] += dic[i]; }
  for (int i = 1; i <= n; i++) {
    if (dic[i] > 0)
      v.push_back(i);
  }
  vector<ll> dp(n + 1);
  dp[1] = 1;
  for (int i = 1; i < n; i++) {
    rep(j, v.size()) {
      if (i + v[j] <= n)
        (dp[i + v[j]] += dp[i]) %= mod;
      else
        break;
    }
  }
  cout << dp[n] << endl;
}

#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

const ll mod = 998244353;

int main() {
  int n;
  cin >> n;
  int k;
  cin >> k;
  vector<pair<int, int>> dic(k);
  rep(i, k) cin >> dic[i].first >> dic[i].second;
  vector<ll> dp(n), sdp(n + 1);
  dp[0] = 1;
  sdp[1] = 1;
  for (int i = 1; i < n; i++) {
    for (auto p : dic) {
      int l = max(0, i - p.second);
      int r = max(0, i - p.first + 1);
      (dp[i] += (mod + sdp[r] - sdp[l]) % mod) %= mod;
    }
    (sdp[i + 1] = sdp[i] + dp[i]) %= mod;
  }
  cout << dp[n - 1] << endl;
}