#include <bits/stdc++.h>
#define rep(i, n) for (int i = (0); i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define limit(x, l, r) max(l, min(x, r))
#define lims(x, l, r) (x = max(l, min(x, r)))
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x, y)                                                            \\
  cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x, y, z)                                                         \\
  cout << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z       \\
       << " = " << (z) << endl
#define showv(v)                                                               \\
  rep(i, v.size()) printf("%d%c", v[i], i == v.size() - 1 ? '\\n' : ' ')
#define showv2(v) rep(j, v.size()) showv(v[j])
#define showt(t, n) rep(i, n) printf("%d%c", t[i], i == n - 1 ? '\\n' : ' ')
#define showt2(t, r, c) rep(j, r) showt(t[j], c)
#define showvp(p) rep(i, p.size()) printf("%d %d\\n", p[i].first, p[i].second)
#define printv(v) rep(i, v.size()) printf("%d\\n", v[i])
#define printt(t, n) rep(i, n) printf("%d\\n", t[i])
#define incl(v, x) (find(all(v), x) != v.end())
#define incls(s, c) (s.find(c) != string::npos)
#define lb(a, x) distance((a).begin(), lower_bound(all(a), (x)))
#define ub(a, x) distance((a).begin(), upper_bound(all(a), (x)))
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n, k) ((n >> k) & 1) // nのk bit目
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define newline puts("")
#define uni(x) x.erase(unique(all(x)), x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vb>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 998244353;
const double EPS = 1e-9;
// const long double EPS = 1e-14;
const int INF = (1 << 30) - 1;
const ll LINF = (1LL << 62) - 1;
#define dame                                                                   \\
  {                                                                            \\
    puts("No");                                                                \\
    return 0;                                                                  \\
  }
#define yn                                                                     \\
  { puts("Yes"); }                                                             \\
  else {                                                                       \\
    puts("No");                                                                \\
  }
#define YN                                                                     \\
  { puts("YES"); }                                                             \\
  else {                                                                       \\
    puts("NO");                                                                \\
  }
inline int in() {
  int x;
  cin >> x;
  return x;
}
inline ll lin() {
  ll x;
  cin >> x;
  return x;
}
inline char chin() {
  char x;
  cin >> x;
  return x;
}
inline string stin() {
  string x;
  cin >> x;
  return x;
}
inline double din() {
  double x;
  cin >> x;
  return x;
}
// template<class T = int> inline T in() { T x; cin >> x; return (x);}
template <typename T> inline ll suma(const vector<T> &a) {
  ll res(0);
  for (auto &&x : a)
    res += x;
  return res;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
char itoa(int n) { return n + '0'; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
const int dy[4] = {0, -1, 0, 1};
const int dx[4] = {1, 0, -1, 0};

ll dp[200005];

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

  map<ll, ll> mp;
  rep(i, k) {
    ll l, r;
    cin >> l >> r;
    l--, r--;
    for (int i = l; i <= r; ++i) {
      if (!mp.count(i))
        mp[i] = i;
    }
  }

  dp[0] = 1;
  rep(i, n) {
    for (auto p : mp) {
      ll j = p.se;
      ll d = j + 1;
      if (i + d > n)
        continue;
      dp[i + d] += dp[i];
      dp[i + d] %= mod;
    }
  }

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

#include <bits/stdc++.h>
#define rep(i, n) for (int i = (0); i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define limit(x, l, r) max(l, min(x, r))
#define lims(x, l, r) (x = max(l, min(x, r)))
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x, y)                                                            \\
  cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x, y, z)                                                         \\
  cout << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z       \\
       << " = " << (z) << endl
#define showv(v)                                                               \\
  rep(i, v.size()) printf("%d%c", v[i], i == v.size() - 1 ? '\\n' : ' ')
#define showv2(v) rep(j, v.size()) showv(v[j])
#define showt(t, n) rep(i, n) printf("%d%c", t[i], i == n - 1 ? '\\n' : ' ')
#define showt2(t, r, c) rep(j, r) showt(t[j], c)
#define showvp(p) rep(i, p.size()) printf("%d %d\\n", p[i].first, p[i].second)
#define printv(v) rep(i, v.size()) printf("%d\\n", v[i])
#define printt(t, n) rep(i, n) printf("%d\\n", t[i])
#define incl(v, x) (find(all(v), x) != v.end())
#define incls(s, c) (s.find(c) != string::npos)
#define lb(a, x) distance((a).begin(), lower_bound(all(a), (x)))
#define ub(a, x) distance((a).begin(), upper_bound(all(a), (x)))
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n, k) ((n >> k) & 1) // nのk bit目
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define newline puts("")
#define uni(x) x.erase(unique(all(x)), x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vb>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const double EPS = 1e-9;
// const long double EPS = 1e-14;
const int INF = (1 << 30) - 1;
const ll LINF = (1LL << 62) - 1;
#define dame                                                                   \\
  {                                                                            \\
    puts("No");                                                                \\
    return 0;                                                                  \\
  }
#define yn                                                                     \\
  { puts("Yes"); }                                                             \\
  else {                                                                       \\
    puts("No");                                                                \\
  }
#define YN                                                                     \\
  { puts("YES"); }                                                             \\
  else {                                                                       \\
    puts("NO");                                                                \\
  }
inline int in() {
  int x;
  cin >> x;
  return x;
}
inline ll lin() {
  ll x;
  cin >> x;
  return x;
}
inline char chin() {
  char x;
  cin >> x;
  return x;
}
inline string stin() {
  string x;
  cin >> x;
  return x;
}
inline double din() {
  double x;
  cin >> x;
  return x;
}
// template<class T = int> inline T in() { T x; cin >> x; return (x);}
template <typename T> inline ll suma(const vector<T> &a) {
  ll res(0);
  for (auto &&x : a)
    res += x;
  return res;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
char itoa(int n) { return n + '0'; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
const int dy[4] = {0, -1, 0, 1};
const int dx[4] = {1, 0, -1, 0};

const int mod = 998244353;
// mint(a).pow(b) -> a^b
struct mint {
  ll x;
  mint(ll x = 0) : x(x % mod) {}
  mint operator-() const { return mint(-x); }
  mint operator~() const { return mint(1) / *this; }
  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;
  }
  bool operator<(const mint &a) const { return x < a.x; }
  bool operator==(const mint &a) const { return x == a.x; }
};
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;
  vi 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) {
      // [l[i], r[i]]
      int li = i - r[j];
      int ri = i - l[j];
      if (ri < 0)
        continue;
      li = max(li, 1);
      dp[i] += dpsum[ri] - dpsum[li - 1]; // dp[li]~dp[ri]
    }
    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)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define limit(x, l, r) max(l, min(x, r))
#define lims(x, l, r) (x = max(l, min(x, r)))
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x, y)                                                            \\
  cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x, y, z)                                                         \\
  cout << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z       \\
       << " = " << (z) << endl
#define showv(v)                                                               \\
  rep(i, v.size()) printf("%d%c", v[i], i == v.size() - 1 ? '\\n' : ' ')
#define showv2(v) rep(j, v.size()) showv(v[j])
#define showt(t, n) rep(i, n) printf("%d%c", t[i], i == n - 1 ? '\\n' : ' ')
#define showt2(t, r, c) rep(j, r) showt(t[j], c)
#define showvp(p) rep(i, p.size()) printf("%d %d\\n", p[i].first, p[i].second)
#define printv(v) rep(i, v.size()) printf("%d\\n", v[i])
#define printt(t, n) rep(i, n) printf("%d\\n", t[i])
#define incl(v, x) (find(all(v), x) != v.end())
#define incls(s, c) (s.find(c) != string::npos)
#define lb(a, x) distance((a).begin(), lower_bound(all(a), (x)))
#define ub(a, x) distance((a).begin(), upper_bound(all(a), (x)))
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n, k) ((n >> k) & 1) // nのk bit目
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define newline puts("")
#define uni(x) x.erase(unique(all(x)), x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vb>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const double EPS = 1e-9;
// const long double EPS = 1e-14;
const int INF = (1 << 30) - 1;
const ll LINF = (1LL << 62) - 1;
#define dame                                                                   \\
  {                                                                            \\
    puts("No");                                                                \\
    return 0;                                                                  \\
  }
#define yn                                                                     \\
  { puts("Yes"); }                                                             \\
  else {                                                                       \\
    puts("No");                                                                \\
  }
#define YN                                                                     \\
  { puts("YES"); }                                                             \\
  else {                                                                       \\
    puts("NO");                                                                \\
  }
inline int in() {
  int x;
  cin >> x;
  return x;
}
inline ll lin() {
  ll x;
  cin >> x;
  return x;
}
inline char chin() {
  char x;
  cin >> x;
  return x;
}
inline string stin() {
  string x;
  cin >> x;
  return x;
}
inline double din() {
  double x;
  cin >> x;
  return x;
}
// template<class T = int> inline T in() { T x; cin >> x; return (x);}
template <typename T> inline ll suma(const vector<T> &a) {
  ll res(0);
  for (auto &&x : a)
    res += x;
  return res;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
char itoa(int n) { return n + '0'; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
const int dy[4] = {0, -1, 0, 1};
const int dx[4] = {1, 0, -1, 0};

const int mod = 998244353;
// mint(a).pow(b) -> a^b
struct mint {
  ll x;
  mint(ll x = 0) : x(x % mod) {}
  mint operator-() const { return mint(-x); }
  mint operator~() const { return mint(1) / *this; }
  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;
  }
  bool operator<(const mint &a) const { return x < a.x; }
  bool operator==(const mint &a) const { return x == a.x; }
};
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;
  vi 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) {
      // [l[i], r[i]]
      int li = i - r[j];
      int ri = i - l[j];
      // if (ri < 0) continue;
      li = max(li, 1);
      dp[i] += dpsum[ri] - dpsum[li - 1]; // dp[li]~dp[ri]
    }
    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 = 1; i <= (n); i++)
using ll = long long;
const int MOD = 998244353;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> s;
  vector<int> dat(n + 10);
  rep(i, k) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++) {
      s.push_back(j);
    }
  }
  sort(s.begin(), s.end());
  dat[1] = 1;
  rep(i, n) {
    if (dat[i] == 0) {
      continue;
    }
    for (int p = 0; p < (int)s.size(); p++) {
      if (i + p <= n) {
        dat[i + s[p]] += dat[i];
        dat[i + s[p]] %= MOD;
      } else {
        s.erase(s.begin() + p);
      }
    }
  }
  cout << dat[n] << endl;
  return 0;
}

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

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

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> l(k), r(k);
  vector<mint> dp(n + 5), sum(n + 5);
  rep(i, k) cin >> l[i] >> r[i];
  dp[1] = 1;
  sum[1] = 1;
  for (int i = 2; i <= n; i++) {
    rep(j, k) {
      int a = i - r[j];
      int b = i - l[j];
      a = max(a, 1);
      if (b < 0)
        continue;
      dp[i] += sum[b] - sum[a - 1];
    }
    sum[i] = dp[i] + sum[i - 1];
  }
  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 p = pair<int, int>;
typedef long long ll;
const ll mod = 998244353;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a;
  int q = 0;
  rep(m, k) {
    int l, r;
    cin >> l >> r;
    for (int o = l; o < r; o++) {
      a[q] = o;
      q++;
    }
  }
  int g = a.size();
  int coun = 0;
  for (int s = 0; s < (1 << g); s++) {
    int sum = 0;
    for (int i = 0; i < g; i++) {
      if ((s >> i) & 1) {
        sum += a[i];
      }
    }
    if (sum == n - 1) {
      coun++;
      coun = coun % mod;
    }
  }
  cout << coun << endl;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
const int MOD = 998244353;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> l(k), r(k), dp(n + 5), sum(n + 5);
  rep(i, k) { cin >> l[i] >> r[i]; }

  dp[1]++;
  sum[1]++;
  for (int i = 2; i <= n; i++) {
    rep(j, k) {
      int a = i - r[j];
      int b = i - l[j];
      a = max(a, 1);
      if (b < 0)
        continue;
      dp[i] += sum[b] - sum[a - 1];
      dp[i] = (dp[i] % MOD + MOD) % MOD;
    }
    sum[i] = dp[i] + sum[i - 1];
    sum[i] = (sum[i] % MOD + MOD) % MOD;
  }
  cout << (dp[n] + MOD) % MOD << endl;
  return 0;
}


#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int, int>;
using PLL = pair<LL, LL>;
using VPI = vector<PII>;
using VPL = vector<PLL>;
using VB = vector<bool>;
using VVB = vector<VB>;
#define REP(i, m, n) for (int i = (m); i < (n); i++)
// i=m -> n-1(昇順)
#define RREP(i, m, n) for (int i = (m); i >= (n); i--)
// i=m -> n(降順)

int main() {
  int n, k;
  cin >> n >> k;
  VI l(k), r(k), list;
  VLL dp(n + 10, 0);
  REP(i, 0, k) {
    cin >> l[i] >> r[i];
    REP(j, l[i], r[i] + 1) {
      list.push_back(j);
      dp[j + 1]++;
    }
  }
  sort(list.begin(), list.end());

  REP(i, list[0], n) {
    for (int x : list) {
      if (i + x <= n) {
        dp[i + x] += dp[i];
        dp[i + x] %= 998244353;
      }
    }
  }

  cout << dp[n] << endl;

  return 0;
}

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int, int>;
using PLL = pair<LL, LL>;
using VPI = vector<PII>;
using VPL = vector<PLL>;
using VB = vector<bool>;
using VVB = vector<VB>;
#define REP(i, m, n) for (int i = (m); i < (n); i++)
#define RREP(i, m, n) for (int i = (m); i >= (n); i--)

int main() {
  int n, k;
  cin >> n >> k;
  VI l(k), r(k);
  VLL dp(n + 10, 0);
  REP(i, 0, k) { cin >> l[i] >> r[i]; }
  dp[1] = 1;
  dp[2] = -1;

  REP(i, 1, n + 1) {
    dp[i] += dp[i - 1];
    dp[i] %= 998244353;
    if (dp[i] < 0) {
      dp[i] += 998244353;
    }
    REP(j, 0, k) {
      if (i + l[j] <= n) {
        dp[i + l[j]] += dp[i];
        dp[i + l[j]] %= 998244353;
      }
      if (i + r[j] + 1 <= n) {
        dp[i + r[j] + 1] -= dp[i];
      }
    }
  }

  cout << dp[n] << endl;

  return 0;
}


#include <bits/stdc++.h>

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

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(x) ((x).begin()), ((x).end())

#define READ(x) (cin >> (x))
#define WRITE_N(x) (cout << (x) << endl)
#define WRITE(x) (cout << (x))
#define WRITE_YESNO(x) (WRITE_N((x) ? "Yes" : "No"))

#define PRECISE_COUT std::cout << std::setprecision(15) << std::fixed

bool xor_logic(bool x, bool y) { return (x && y) || (!x && !y); }

#define DIVIDER 998244353

ll solve(ll N, ll K, vector<ll> &L, vector<ll> &R) {
  //
  //
  vector<ll> num_list;
  for (size_t i = 0; i < K; i++) {
    for (size_t j = L[i]; j <= R[i]; j++) {
      num_list.push_back(j);
    }
  }
  sort(ALL(num_list));

  vector<ll> pattern_count(N, 0);
  pattern_count[0] = 1;
  for (ll i = 1; i <= N - 1; i++) {
    for (auto &&x : num_list) {
      if (x > i) {
        break;
      }

      pattern_count[i] += pattern_count[i - x];
    }

    pattern_count[i] %= DIVIDER;
  }

  return pattern_count[N - 1];
}

int main() {
  // get values from input
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll N, K;
  cin >> N >> K;

  std::vector<ll> L(K, 0), R(K, 0);
  for (size_t i = 0; i < K; i++) {
    cin >> L[i] >> R[i];
  }

  // main procedure
  ll ans = solve(N, K, L, R);

  // output
  cout << ans << endl;

  return 0;
}

#include <bits/stdc++.h>

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

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(x) ((x).begin()), ((x).end())

#define READ(x) (cin >> (x))
#define WRITE_N(x) (cout << (x) << endl)
#define WRITE(x) (cout << (x))
#define WRITE_YESNO(x) (WRITE_N((x) ? "Yes" : "No"))

#define PRECISE_COUT std::cout << std::setprecision(15) << std::fixed

bool xor_logic(bool x, bool y) { return (x && y) || (!x && !y); }

#define DIVIDER 998244353

ll solve(ll N, ll K, vector<ll> &L, vector<ll> &R) {
  // vector<ll> num_list;
  // for (size_t i = 0; i < K; i++) {
  //   for (size_t j = L[i]; j <= R[i]; j++) {
  //     num_list.push_back(j);
  //   }
  // }
  vector<ll> pattern_count(N, 0);
  vector<ll> pattern_count_sum(N, 0);
  pattern_count[0] = 1;
  pattern_count_sum[0] = 1;

  for (ll i = 1; i <= N - 1; i++) {
    for (size_t j = 0; j < K; j++) {
      ll l = L[j];
      ll r = R[j];

      if (l > i) {
        continue;
      }
      if (r > i) {
        r = i;
      }

      pattern_count[i] += (pattern_count_sum[i - l] -
                           (r != i ? pattern_count_sum[i - r - 1] : 0)) +
                          DIVIDER;
    }

    pattern_count[i] %= DIVIDER;
    pattern_count_sum[i] =
        (pattern_count[i] + pattern_count_sum[i - 1]) % DIVIDER;
  }

  return pattern_count[N - 1];
}

int main() {
  // get values from input
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll N, K;
  cin >> N >> K;

  std::vector<ll> L(K, 0), R(K, 0);
  for (size_t i = 0; i < K; i++) {
    cin >> L[i] >> R[i];
  }

  // main procedure
  ll ans = solve(N, K, L, R);

  // output
  cout << ans << endl;

  return 0;
}


#include <bits/stdc++.h>
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << #x << ": " << x << endl
using namespace std;
using ll = long long;
const ll MOD = 998244353;
const ll LINF = LLONG_MAX;
const int INF = INT_MAX;
const double PI = acos(-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;
}

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> A;

  rep(i, 0, k) {
    ll a, b;
    cin >> a >> b;
    rep(j, a, b + 1) { A.push_back(j); }
  }

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

  rep(i, 1, n + 1) {
    for (auto j : A) {
      if (i - j >= 0) {
        dp[i] = (dp[i] + (dp[i - j] % MOD)) % MOD;
      }
    }
  }

  /* rep(i,0,n){
          debug(dp[i]);

  }
  */
  ll ans = dp[n] % MOD;
  cout << ans << endl;
}

#include <bits/stdc++.h>
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << #x << ": " << x << endl
using namespace std;
using ll = long long;
const ll MOD = 998244353;
const ll LINF = LLONG_MAX;
const int INF = INT_MAX;
const double PI = acos(-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;
}

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> A;
  vector<pair<ll, ll>> LR;
  rep(i, 0, k) {
    ll a, b;
    cin >> a >> b;
    LR.push_back(make_pair(a, b));
    rep(j, a, b + 1) { A.push_back(j); }
  }

  vector<ll> dp(200010, 0);
  dp[1]++;

  rep(i, 1, n + 10) {
    if (i != 2)
      dp[i] = (dp[i - 1] % MOD + dp[i] % MOD) % MOD;
    if (dp[i] >= 1) {
      for (auto p : LR) {
        ll l = p.first;
        ll r = p.second;
        if (l + i <= n + 10) {
          dp[l + i] = ((dp[l + i] + (dp[i] % MOD)) % MOD + MOD) % MOD;
        }
        if (r + i <= n + 10) {
          dp[r + i + 1] = ((dp[r + i + 1] - (dp[i] % MOD)) % MOD + MOD) % MOD;
        }
      }
    }
  }

  /* rep(i,1,n + 1){
          debug(dp[i]);
  }
  */

  ll ans = (dp[n] % MOD + MOD) % MOD;
  cout << ans << endl;
}


// #include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define free                                                                   \\
  freopen("input.txt", "r", stdin);                                            \\
  freopen("output.txt", "w", stdout);
#define Fast                                                                   \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);
#define pb push_back
#define mp make_pair
#define F first
#define S second

bool vowel(char che) {
  if (che == 'A' || che == 'E' || che == 'I' || che == 'O' || che == 'U' ||
      che == 'Y')
    return true;
  else
    return false;
}

const int N = 1e6 + 5;
const int mod = 998244353;
ll a[N], l[N], r[N], b[N], c[N], d, dp[N], dis, tree[N];
pair<ll, ll> p[N];
char o;
bool mark[N], h;
string s, s1;
stack<int> st;
set<ll> st1, st2;
deque<int> dq;
vector<int> vt, vs, vm;
// int a1[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

int main() {
  Fast ll t = 0, n, m = 0, k = 0, f = 0, sum = 0, ans = 0, n1 = 0;
  cin >> n >> n1;
  for (int i = 0; i < n1; i++) {
    cin >> p[i].F >> p[i].S;
  }
  sort(p, p + n1);
  t = 0;
  for (int i = 0; i < n1; i++) {
    t = max(t, p[i].F);
    for (int j = t; j <= p[i].S; j++) {
      a[j] = 1;
    }
    t = max(t, p[i].S);
  }
  for (int i = 1; i <= 2e5 + 5; i++) {
    if (a[i] == 1) {

      b[m++] = i;
    }
  }
  for (int i = 0; i < m; i++) {
    dp[b[i] + 1] = 1;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < m; j++) {
      if ((i - b[j]) > 0)
        dp[i] += dp[i - b[j]];
      dp[i] %= mod;
    }
  }
  cout << dp[n] << endl;
}

// #include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define free                                                                   \\
  freopen("input.txt", "r", stdin);                                            \\
  freopen("output.txt", "w", stdout);
#define Fast                                                                   \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);
#define pb push_back
#define mp make_pair
#define F first
#define S second

bool vowel(char che) {
  if (che == 'A' || che == 'E' || che == 'I' || che == 'O' || che == 'U' ||
      che == 'Y')
    return true;
  else
    return false;
}

const int N = 2e5 + 5;
const int mod = 998244353;
ll a[N], l[N], r[N], b[N], c[N], d, dp[N], dis, pr[N];
pair<ll, ll> p[N];
char o;
bool mark[N], h;
string s, s1;
stack<int> st;
set<ll> st1, st2;
deque<int> dq;
vector<int> vt, vs, vm;
// int a1[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

int main() {
  Fast ll t = 0, n, m = 0, k = 0, f = 0, sum = 0, ans = 0, n1 = 0;
  cin >> n >> n1;
  ll mn = 1e6;
  for (int i = 0; i < n1; i++) {
    cin >> p[i].F >> p[i].S;
    mn = min(mn, p[i].F);
  }
  sort(p, p + n1);
  dp[mn + 1] = 1;
  pr[mn + 1] = 2;
  for (int i = 1; i <= mn; i++) {
    pr[i] = 1;
  }
  for (int i = mn + 2; i <= n; i++) {
    ll mx = 0;
    for (int j = 0; j < n1; j++) {
      mx = max(mx, p[j].F);
      if (p[j].S >= mx) {
        dp[i] += pr[i - mx] - pr[max(ll(0), i - p[j].S - 1)];
        dp[i] %= mod;
      }
      mx = max(p[j].S, mx);
    }
    pr[i] = pr[i - 1] + dp[i];
    pr[i] %= mod;
  }
  cout << (dp[n] + mod) % mod << endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef unsigned int INT;
typedef unsigned long long LONG;
typedef long long LL;
typedef pair<int, int> PII;
const int N = 1e5 + 10;
const int mod = 998244353;
#define debug(x) cerr << #x << ": " << (x) << '\\n'
#define FW freopen("data2.txt", "w", stdout);
// 快速读入输出，只适用于整数，使用时流同步打开，C语言不准关流
//  getchar()<<cin(关流)<<scanf()<<cin
template <class T> inline bool Read(T &ret) {
  char c;
  int sgn;
  if (static_cast<void>(c = getchar()), c == EOF)
    return 0;
  while (c != '-' && (c < '0' || c > '9'))
    c = getchar();
  sgn = (c == '-') ? -1 : 1;
  ret = (c == '-') ? 0 : (c - '0');
  while (static_cast<void>(c = getchar()), c >= '0' && c <= '9')
    ret = ret * 10 + (c - '0');
  ret *= sgn;
  return 1;
}
// 输出只能用于整数
template <class T> inline void Write(T x) {
  if (x < 0)
    putchar('-'), x = -x;
  if (x > 9)
    Write(x / 10);
  putchar(x % 10 + '0');
}

int dp[N * 2] = {0};
void slove(int question_num) {
  int n, k;
  cin >> n >> k;
  unordered_map<int, int> num;
  for (int i = 1; i <= k; ++i) {
    int a, b;
    cin >> a >> b;
    num[a] = b;
  }
  dp[1] = 1;
  for (int i = 2; i <= n; ++i) {
    for (auto j : num) {
      for (int k = j.first; k <= j.second; ++k) {
        int cur = i - k;
        if (cur <= 0)
          break;
        dp[i] = (dp[i] + dp[cur]) % mod;
      }
    }
  }
  cout << (dp[n] % mod) << endl;
}

int main() {
  int num = 1;
  // cin >> num;
  for (int i = 1; i <= num; ++i) {
    slove(i);
  }
  // system("pause");
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef unsigned int INT;
typedef unsigned long long LONG;
typedef long long LL;
typedef pair<int, int> PII;
const int N = 1e5 + 10;
const int mod = 998244353;
#define debug(x) cerr << #x << ": " << (x) << '\\n'
#define FW freopen("data2.txt", "w", stdout);
// 快速读入输出，只适用于整数，使用时流同步打开，C语言不准关流
//  getchar()<<cin(关流)<<scanf()<<cin
template <class T> inline bool Read(T &ret) {
  char c;
  int sgn;
  if (static_cast<void>(c = getchar()), c == EOF)
    return 0;
  while (c != '-' && (c < '0' || c > '9'))
    c = getchar();
  sgn = (c == '-') ? -1 : 1;
  ret = (c == '-') ? 0 : (c - '0');
  while (static_cast<void>(c = getchar()), c >= '0' && c <= '9')
    ret = ret * 10 + (c - '0');
  ret *= sgn;
  return 1;
}
// 输出只能用于整数
template <class T> inline void Write(T x) {
  if (x < 0)
    putchar('-'), x = -x;
  if (x > 9)
    Write(x / 10);
  putchar(x % 10 + '0');
}

LL dp[N * 2] = {0};
int lowbit(int x) { return (x & -x); }
void add(int x, int val) {
  for (int i = x; i < 2 * N; i += lowbit(i)) {
    dp[i] = (dp[i] % mod + val) % mod;
  }
}
LL sum(int x) {
  LL ans = 0;
  while (x) {
    ans = (ans % mod + dp[x]) % mod;
    x -= lowbit(x);
  }
  return ans % mod;
}

LL rang_sum(int l, int r) { return (sum(r) - sum(l - 1)) + mod; }
void slove(int question_num) {
  int n, k;
  cin >> n >> k;
  unordered_map<int, int> num;
  for (int i = 1; i <= k; ++i) {
    int a, b;
    cin >> a >> b;
    num[a] = b;
  }
  add(1, 1);
  for (int i = 2; i <= n; ++i) {
    for (auto j : num) {
      int a = j.first, b = j.second;
      if (a >= i)
        continue;
      if (b >= i) {
        LL cur = rang_sum(1, i - a);
        add(i, cur);
      } else {
        LL cur = rang_sum(i - b, i - a);
        add(i, cur);
      }
    }
  }
  cout << (rang_sum(n, n) % mod) << endl;
}

int main() {
  int num = 1;
  // cin >> num;
  for (int i = 1; i <= num; ++i) {
    slove(i);
  }
  // system("pause");
  return 0;
}


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

using ll = long long;
// print(fixed << setprecision(10));
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repk(i, n, k) for (ll i = k; i < (n); i++)
#define all(n) n.begin(), n.end()
#define print(n) cout << n << endl
double PI = acos(-1.0);
int INF = 1e9;
ll LINF = 1e18;
ll MOD = 1e9 + 7;
ll mods = 998244353;

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

  ll n;
  int k;
  cin >> n >> k;
  vector<ll> s(k * 2);
  ll l, r;
  rep(i, k) {
    cin >> l >> r;
    s[i * 2] = l;
    s[i * 2 + 1] = r;
  }
  vector<ll> tb(n + 1, 0);
  tb[1] = 1;
  for (ll i = 1; i < n; i++) {
    if (tb[i] == 0)
      continue;
    rep(j, k) {
      l = s[j * 2];
      r = s[j * 2 + 1];
      rep(m, r - l + 1) {
        if (i + l + m > n)
          break;
        tb[i + l + m] += tb[i];
        if (tb[i + l + m] > mods)
          tb[i + l + m] %= mods;
      }
    }
  }
  print(tb[n]);
  return 0;
}

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

using ll = long long;
// print(fixed << setprecision(10));
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repk(i, n, k) for (ll i = k; i < (n); i++)
#define all(n) n.begin(), n.end()
#define print(n) cout << n << endl
double PI = acos(-1.0);
int INF = 1e9;
ll LINF = 1e18;
ll MOD = 1e9 + 7;
ll mods = 998244353;

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

  ll n;
  int k;
  cin >> n >> k;
  vector<ll> s(k * 2);
  ll l, r;
  rep(i, k) {
    cin >> l >> r;
    s[i * 2] = l;
    s[i * 2 + 1] = r;
  }
  ll sum = 0;
  vector<ll> tb(n + 1, 0);
  tb[1] = 1;
  tb[2] = -1;
  for (ll i = 1; i <= n; i++) {
    sum = (tb[i] + sum + mods) % mods;
    rep(j, k) {
      l = s[j * 2];
      r = s[j * 2 + 1];
      if (i + l <= n)
        tb[i + l] = (tb[i + l] + sum) % mods;
      if (i + r < n)
        tb[i + r + 1] = (tb[i + r + 1] - sum) % mods;
    }
  }
  print(sum);
  return 0;
}


#include <algorithm>
#include <iostream>
#include <vector>
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
#define MOD 998244353
using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  vector<pair<int, int>> v, tmp;
  for (int i = 0; i < k; i++) {
    int x, y;
    cin >> x >> y;
    tmp.push_back({x, y});
  }
  sort(all(tmp));
  int px = 0, py = 0;
  for (auto g : tmp) {
    if (g.ff <= py) {
      py = g.ss;
    } else {
      if (px != 0 && py != 0)
        v.push_back({px, py});
      px = g.ff;
      py = g.ss;
    }
  }
  v.push_back({px, py});
  vector<int> A(n + 1);
  A[1] = 1;
  A[2] = -1;
  for (int i = 1; i <= n; i++) {
    A[i] += A[i - 1];
    if (A[i] >= MOD)
      A[i] -= MOD;
    for (auto g : v) {
      A[i + g.ff] += A[i];
      if (A[i + g.ff] >= MOD)
        A[i + g.ff] -= MOD;
      A[i + g.ss + 1] -= A[i];
      if (A[i + g.ss + 1] < 0)
        A[i + g.ss + 1] += MOD;
    }
  }
  cout << A[n];
}

#include <algorithm>
#include <iostream>
#include <vector>
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
#define MOD 998244353
using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  vector<pair<int, int>> v, tmp;
  for (int i = 0; i < k; i++) {
    int x, y;
    cin >> x >> y;
    tmp.push_back({x, y});
  }
  sort(all(tmp));
  int px = 0, py = 0;
  for (auto g : tmp) {
    if (g.ff <= py) {
      py = g.ss;
    } else {
      if (px != 0 && py != 0)
        v.push_back({px, py});
      px = g.ff;
      py = g.ss;
    }
  }
  v.push_back({px, py});
  vector<int> A(n + 1);
  A[1] = 1;
  A[2] = -1;
  for (int i = 1; i <= n; i++) {
    A[i] += A[i - 1];
    if (A[i] >= MOD)
      A[i] -= MOD;
    for (auto g : v) {
      if (i + g.ff <= n) {
        A[i + g.ff] += A[i];
        if (A[i + g.ff] >= MOD)
          A[i + g.ff] -= MOD;
      }
      if (i + g.ss + 1 <= n) {
        A[i + g.ss + 1] -= A[i];
        if (A[i + g.ss + 1] < 0)
          A[i + g.ss + 1] += MOD;
      }
    }
  }
  cout << A[n];
}


/*
                ******

        Author: Nguyen Phuc Chuong

                ******
*/

#include <bits/stdc++.h>

using namespace std;

long long a[10][2];
long long dp[200000];
const long long mod = 998244353;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < k; i++) {
    cin >> a[i][0] >> a[i][1];
  }
  dp[0] = 1;
  dp[1] = -1;
  for (int i = 0; i < n; i++) {
    if (i > 0) {
      dp[i] = (dp[i] + dp[i - 1]) % mod;
    }
    for (int j = 0; j < k; j++) {
      dp[i + a[j][0]] = (dp[i + a[j][0]] + dp[i]) % mod;
      dp[i + a[j][1] + 1] = (dp[i + a[j][1] + 1] - dp[i]) % mod;
      if (dp[i + a[j][1] + 1] < 0) {
        dp[i + a[j][1] + 1] += mod;
      }
    }
  }
  cout << dp[n - 1];
  return 0;
}


// is there any case of -1 or any special corner cases ?
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int>
#define pi pair<int, int>
#define all(v) v.begin(), v.end()
#define zeros(arr) memset(arr, 0, sizeof(arr));
#define precise(num)                                                           \\
  cout << fixed;                                                               \\
  cout << std::setprecision(num)
#define nl cout << "\\n";
#define test                                                                   \\
  int t;                                                                       \\
  cin >> t;                                                                    \\
  while (t--)
const int maxx = 3 * 1e5, limit = 9 * 1e18, MOD = 998244353;
#define boost                                                                  \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define endl '\\n';
int32_t main() {
  boost;
  int n, k;
  cin >> n >> k;
  set<int> s;
  for (int i = 0; i < k; i++) {
    int a, b;
    cin >> a >> b;
    for (int i = a; i <= b; i++) {
      s.insert(i);
    }
  }
  int len = s.size();
  int itr = 0;
  int arr[len + 1];
  for (auto x : s) {
    arr[itr++] = x;
  }
  int dp[n + 2];
  zeros(dp);
  dp[1] = 1;
  dp[0] = 0;
  for (int i = 2; i <= n; i++) {

    for (int j = 0; j < len; j++) {
      int x = arr[j];
      if (x > i)
        break;

      dp[i] = (dp[i - x] + dp[i]) % MOD;
    }
  }
  cout << dp[n] << endl;
}

// is there any case of -1 or any special corner cases ?
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int>
#define pi pair<int, int>
#define all(v) v.begin(), v.end()
#define zeros(arr) memset(arr, 0, sizeof(arr));
#define precise(num)                                                           \\
  cout << fixed;                                                               \\
  cout << std::setprecision(num)
#define nl cout << "\\n";
#define test                                                                   \\
  int t;                                                                       \\
  cin >> t;                                                                    \\
  while (t--)
const int maxx = 3 * 1e5, limit = 9 * 1e18, MOD = 998244353;
#define boost                                                                  \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define endl '\\n';
int32_t main() {
  boost;
  int n, k;
  cin >> n >> k;
  map<int, int> mark;
  for (int i = 0; i < k; i++) {
    int a, b;
    cin >> a >> b;
    for (int i = a; i <= b; i++) {
      mark[i] = 1;
    }
  }
  int l, r;
  bool flag = false;
  vector<pair<int, int>> range;
  for (int i = 1; i <= 1e6; i++) {

    if (mark[i] == 1) {
      if (!flag) {
        l = i;
        flag = true;
      }
    } else {
      if (flag) {
        r = i - 1;
        flag = false;
        range.pb(mp(l, r));
      }
    }
  }

  // for(int i=0 ; i< range.size() ; i++ ){
  //     cout<<range[i].fi<<" "<<range[i].se<<endl;
  // }

  int dp[n + 2];
  zeros(dp);
  dp[1] = 1;
  dp[0] = 0;
  int pre[n + 2];
  zeros(pre);

  pre[0] = 0;
  pre[1] = 1;

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

    for (int j = 0; j < range.size(); j++) {

      int l = range[j].fi;
      int r = range[j].se;
      // cout<<l<<

      if (l >= i)
        continue;

      l = i - l;
      r = i - r;

      if (r < 1)
        r = 1;

      // cout<<l<<" "<<r<<endl;
      int minl = min(l, r);
      int maxr = max(l, r);

      dp[i] = (dp[i] + (pre[maxr] - pre[minl - 1] + 2 * MOD) % MOD) % MOD;
    }

    pre[i] = (pre[i - 1] + dp[i]) % MOD;
  }

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


#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#define debug_value(x)                                                         \\
  cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x     \\
       << endl;
#define debug(x)                                                               \\
  cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

using namespace std;
typedef long long ll;

const ll MOD = 998244353;

int N, K;
int L[10], R[10];

ll cnt[200005];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(10) << fixed;
  cin >> N >> K;
  for (int i = 0; i < K; i++) {
    cin >> L[i] >> R[i];
  }
  cnt[0] = 1;
  cnt[1] = -1;
  for (int i = 0; i < N; i++) {
    if (i > 0)
      cnt[i] += cnt[i - 1];
    cnt[i] %= MOD;
    for (int j = 0; j < K; j++) {
      cnt[i + L[j]] += cnt[i];
      cnt[i + L[j]] %= MOD;
      cnt[i + R[j] + 1] -= cnt[i];
      cnt[i + R[j] + 1] %= MOD;
    }
  }
  cout << (cnt[N - 1] + MOD) % MOD << endl;
}

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#define debug_value(x)                                                         \\
  cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x     \\
       << endl;
#define debug(x)                                                               \\
  cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

using namespace std;
typedef long long ll;

const ll MOD = 998244353;

int N, K;
int L[10], R[10];

ll cnt[500005];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(10) << fixed;
  cin >> N >> K;
  for (int i = 0; i < K; i++) {
    cin >> L[i] >> R[i];
  }
  cnt[0] = 1;
  cnt[1] = -1;
  for (int i = 0; i < N; i++) {
    if (i > 0)
      cnt[i] += cnt[i - 1];
    cnt[i] %= MOD;
    for (int j = 0; j < K; j++) {
      cnt[i + L[j]] += cnt[i];
      cnt[i + L[j]] %= MOD;
      cnt[i + R[j] + 1] -= cnt[i];
      cnt[i + R[j] + 1] %= MOD;
    }
  }
  cout << (cnt[N - 1] + MOD) % MOD << endl;
}


/*
        ID: sixathofpain
        TASK: friday
        LANG: C++

*/

// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define all(x) (x).begin(), (x).end()
#define ff first
#define ss second
#define setbits(x) __builtin_popcount(x)
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<db, db> pdd;
typedef vector<int> vi;
#define m1 make_pair
#define in insert
#define pb push_back
#define IOS                                                                    \\
  std::ios::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define endl "\\n"
template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

inline ll gcd(ll a, ll b) {
  if (a == 0)
    return b;
  return gcd(b % a, a);
}
inline ll power(ll a, ll n, ll m) {
  if (n == 0)
    return 1;
  ll p = power(a, n / 2, m);
  p = (p * p) % m;
  if (n % 2)
    return (p * a) % m;
  else
    return p;
}
const ll MOD = 998244353;
const int N = int(2e5) + 999;
#define int long long int

int ans[N];

int32_t main() {
  IOS;

  // freopen("friday.in","r",stdin);
  // freopen("friday.out","w",stdout);

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

  vector<pii> v(k);
  for (int i = 0; i < k; i++)
    cin >> v[i].ff >> v[i].ss;
  ans[1] = 1;
  ans[2] = -1;
  int tmp = 0;

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

    tmp = tmp + ans[i];
    tmp %= MOD;
    if (tmp < 0)
      tmp += MOD;

    // cout<<i<<" "<<ans[i]<<" "<<tmp<<endl;

    ans[i] = tmp;

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

      int x = i + v[j].ff;
      int y = i + v[j].ss + 1;
      if (x <= n) {
        ans[x] += tmp;
        ans[x] %= MOD;
      }
      if (y <= n) {
        ans[y] -= tmp;
        ans[y] %= MOD;
      }

      if (x <= n and ans[x] < 0)
        ans[x] += MOD;

      if (ans[y] < 0 and y <= n)
        ans[y] += MOD;
      // cerr<<"for i "<<x<<" "<<ans[x]<<" "<<y<<" "<<ans[y]<<endl;
    }
  }
  cout << ans[n] << endl;

  return 0;
}

/*
        ID: sixathofpain
        TASK: friday
        LANG: C++

*/

// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define all(x) (x).begin(), (x).end()
#define ff first
#define ss second
#define setbits(x) __builtin_popcount(x)
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<db, db> pdd;
typedef vector<int> vi;
#define m1 make_pair
#define in insert
#define pb push_back
#define IOS                                                                    \\
  std::ios::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define endl "\\n"
template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

inline ll gcd(ll a, ll b) {
  if (a == 0)
    return b;
  return gcd(b % a, a);
}
inline ll power(ll a, ll n, ll m) {
  if (n == 0)
    return 1;
  ll p = power(a, n / 2, m);
  p = (p * p) % m;
  if (n % 2)
    return (p * a) % m;
  else
    return p;
}
const ll MOD = 998244353;
const int N = int(2e5) + 999;
#define int long long int

int ans[N];

int32_t main() {
  IOS;

  // freopen("friday.in","r",stdin);
  // freopen("friday.out","w",stdout);

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

  vector<pii> v(k);

  for (int i = 0; i < k; i++)
    cin >> v[i].ff >> v[i].ss;

  ans[1] = 1;
  ans[2] = -1;
  int tmp = 0;

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

    tmp = tmp + ans[i];
    tmp %= MOD;
    if (tmp < 0)
      tmp += MOD;

    ans[i] = tmp;

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

      int x = i + v[j].ff;
      int y = i + v[j].ss + 1;
      if (x <= n) {
        ans[x] += tmp;
        ans[x] %= MOD;
      }
      if (y <= n) {
        ans[y] -= tmp;
        ans[y] %= MOD;
      }

      if (x <= n) {
        if (ans[x] < 0)
          ans[x] += MOD;
      }

      if (y <= n) {
        if (ans[y] < 0)
          ans[y] += MOD;
      }
      // cerr<<"for i "<<x<<" "<<ans[x]<<" "<<y<<" "<<ans[y]<<endl;
    }
  }
  cout << ans[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>;

const ll mod = 998244353;

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

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint &operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream &operator>>(istream &is, mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> L(k);
  vector<int> R(k);
  rep(i, k) { cin >> L[i] >> R[i]; }
  vector<mint> dp(n, 0);
  vector<mint> dpsum(n, 0);
  dpsum[0] = 1;
  dp[0] = 1;
  for (int i = 1; i < n; i++) {
    rep(j, k) {
      if (i - L[j] < 0) {
        continue;
      } else if (i - R[i] - 1 < 0) {
        dp[i] += dpsum[i - L[j]];

      } else {
        dp[i] += dpsum[i - L[j]] - dpsum[i - R[j] - 1];
      }
    }
    dpsum[i] = dpsum[i - 1] + dp[i];
  }
  cout << dp[n - 1] << endl;
}

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

const ll mod = 998244353;

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

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint &operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream &operator>>(istream &is, mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> L(k);
  vector<int> R(k);
  rep(i, k) { cin >> L[i] >> R[i]; }
  vector<mint> dp(n + 1);
  vector<mint> dpsum(n + 1);
  dpsum[1] = 1;
  dp[1] = 1;
  for (int i = 2; i < n + 1; i++) {
    rep(j, k) {
      int li = i - R[j];
      int ri = i - L[j];
      if (ri < 0)
        continue;
      li = max(1, li);
      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 MOD 998244353
#define ll long long
using namespace std;
ll ff[200100];
#define MAXN 100010
int x[200100], y[200100];
unsigned ll n, m, ans[MAXN << 2], tag[MAXN << 2];
inline ll ls(ll x) { return x << 1; }
inline ll rs(ll x) { return x << 1 | 1; }
inline void push_up(ll p) { ans[p] = ans[ls(p)] + ans[rs(p)]; }
void build(ll p, ll l, ll r) {
  tag[p] = 0;
  if (l == r) {
    ans[p] = ff[l];
    return;
  }
  ll mid = (l + r) >> 1;
  build(ls(p), l, mid);
  build(rs(p), mid + 1, r);
  push_up(p);
}
inline void f(ll p, ll l, ll r, ll k) {
  tag[p] = (tag[p] + k) % MOD;
  ans[p] = ans[p] % MOD + k % MOD * (r - l + 1) % MOD;
}
inline void push_down(ll p, ll l, ll r) {
  ll mid = (l + r) >> 1;
  f(ls(p), l, mid, tag[p]);
  f(rs(p), mid + 1, r, tag[p]);
  tag[p] = 0;
}
inline void update(ll nl, ll nr, ll l, ll r, ll p, ll k) {
  if (nl <= l && r <= nr) {
    ans[p] += (k * (r - l + 1) % MOD);
    tag[p] += k % MOD;
    return;
  }
  push_down(p, l, r);
  ll mid = (l + r) >> 1;
  if (nl <= mid)
    update(nl, nr, l, mid, ls(p), k);
  if (nr > mid)
    update(nl, nr, mid + 1, r, rs(p), k);
  push_up(p);
}
ll query(ll q_x, ll q_y, ll l, ll r, ll p) {
  if (q_x + q_y == 0)
    return 0;
  ll res = 0;
  if (q_x <= l && r <= q_y)
    return ans[p];
  ll mid = (l + r) >> 1;
  push_down(p, l, r);
  if (q_x <= mid)
    res += query(q_x, q_y, l, mid, ls(p));
  if (q_y > mid)
    res += query(q_x, q_y, mid + 1, r, rs(p));
  return res;
}
int main() {
  int n, m;
  cin >> n >> m;
  memset(ff, 0, sizeof ff);
  ff[1] = 1;
  ff[0] = 0;
  build(1, 1, n);
  for (int i = 1; i <= m; i++) {
    int p, q;
    cin >> p >> q;
    x[i] = p, y[i] = q;
  }

  for (int i = 2; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      ll g = max(0, i - x[j]), yy = max(0, i - y[j]);
      ll ans = (query(yy, g, 1, n, 1)) % MOD;
      update(i, i, 1, n, 1, ans);
    }
  }
  cout << (query(n, n, 1, n, 1) % MOD);
  return 0;
}

#include <bits/stdc++.h>
#define MOD 998244353
#define ll long long
using namespace std;
ll ff[200100];
#define MAXN 200010
int x[200100], y[200100];
unsigned ll n, m, ans[MAXN << 2], tag[MAXN << 2];
inline ll ls(ll x) { return x << 1; }
inline ll rs(ll x) { return x << 1 | 1; }
inline void push_up(ll p) { ans[p] = ans[ls(p)] + ans[rs(p)]; }
void build(ll p, ll l, ll r) {
  tag[p] = 0;
  if (l == r) {
    ans[p] = ff[l];
    return;
  }
  ll mid = (l + r) >> 1;
  build(ls(p), l, mid);
  build(rs(p), mid + 1, r);
  push_up(p);
}
inline void f(ll p, ll l, ll r, ll k) {
  tag[p] = (tag[p] + k) % MOD;
  ans[p] = ans[p] % MOD + k % MOD * (r - l + 1) % MOD;
}
inline void push_down(ll p, ll l, ll r) {
  ll mid = (l + r) >> 1;
  f(ls(p), l, mid, tag[p]);
  f(rs(p), mid + 1, r, tag[p]);
  tag[p] = 0;
}
inline void update(ll nl, ll nr, ll l, ll r, ll p, ll k) {
  if (nl <= l && r <= nr) {
    ans[p] += (k * (r - l + 1) % MOD);
    tag[p] += k % MOD;
    return;
  }
  push_down(p, l, r);
  ll mid = (l + r) >> 1;
  if (nl <= mid)
    update(nl, nr, l, mid, ls(p), k);
  if (nr > mid)
    update(nl, nr, mid + 1, r, rs(p), k);
  push_up(p);
}
ll query(ll q_x, ll q_y, ll l, ll r, ll p) {
  if (q_x + q_y == 0)
    return 0;
  ll res = 0;
  if (q_x <= l && r <= q_y)
    return ans[p];
  ll mid = (l + r) >> 1;
  push_down(p, l, r);
  if (q_x <= mid)
    res += query(q_x, q_y, l, mid, ls(p));
  if (q_y > mid)
    res += query(q_x, q_y, mid + 1, r, rs(p));
  return res;
}
int main() {
  int n, m;
  cin >> n >> m;
  memset(ff, 0, sizeof ff);
  ff[1] = 1;
  ff[0] = 0;
  build(1, 1, n);
  for (int i = 1; i <= m; i++) {
    int p, q;
    cin >> p >> q;
    x[i] = p, y[i] = q;
  }

  for (int i = 2; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      ll g = max(0, i - x[j]), yy = max(0, i - y[j]);
      ll ans = (query(yy, g, 1, n, 1)) % MOD;
      update(i, i, 1, n, 1, ans);
    }
  }
  cout << (query(n, n, 1, n, 1) % MOD);
  return 0;
}


// {{{ Boilerplate Code <--------------------------------------------------
// vim:filetype=cpp:foldmethod=marker:foldmarker={{{,}}}

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

#define FOR(I, A, B) for (int I = (A); I < (B); ++I)
#define ALL(A) (A).begin(), (A).end()

#define MOD 998244353
using namespace std;

// }}}

int main() {
  int N, K;

  cin >> N >> K;
  vector<pair<int, int>> seg;

  FOR(i, 0, K) {
    int L, R;
    cin >> L >> R;
    seg.push_back(pair<int, int>(L, R));
  }

  long long cur = 0;

  long long a[300000];

  FOR(i, 0, N + 1) a[i] = 0;
  a[0] = 1;
  a[1] = -1;

  FOR(i, 0, N) {
    cur = (cur + a[i]) % MOD;
    FOR(j, 0, seg.size()) {
      a[i + seg[j].first] = (a[i + seg[j].first] + cur) % MOD;
      a[i + seg[j].second + 1] = (a[i + seg[j].second + 1] - cur) % MOD;
    }
  }

  cout << (cur + MOD) % MOD << endl;
}

// {{{ Boilerplate Code <--------------------------------------------------
// vim:filetype=cpp:foldmethod=marker:foldmarker={{{,}}}

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

#define FOR(I, A, B) for (int I = (A); I < (B); ++I)
#define ALL(A) (A).begin(), (A).end()

#define MOD 998244353
using namespace std;

// }}}

int main() {
  int N, K;

  cin >> N >> K;
  vector<pair<int, int>> seg;

  FOR(i, 0, K) {
    int L, R;
    cin >> L >> R;
    seg.push_back(pair<int, int>(L, R));
  }

  long long cur = 0;

  long long a[500000];

  FOR(i, 0, N + 1) a[i] = 0;
  a[0] = 1;
  a[1] = -1;

  FOR(i, 0, N) {
    cur = (cur + a[i]) % MOD;
    FOR(j, 0, seg.size()) {
      a[i + seg[j].first] = (a[i + seg[j].first] + cur) % MOD;
      a[i + seg[j].second + 1] = (a[i + seg[j].second + 1] - cur) % MOD;
    }
  }

  cout << (cur + MOD) % MOD << endl;
}


/*
 *  TEMPLATE BY LOUIS NAVARRO
 *  FREE OF USE
 *  (inspired by other templates)
 */
#include <bits/stdc++.h>

using namespace std;

/*
 *
 * TYPE DEFINITIONS
 *
 */
// Basic types
#define uint unsigned int
#define ull unsigned long long
#define ll long long
#define ld long double
// Vectors
#define vt vector
#define vti vector<int>
#define vtl vector<long long>
#define vtd vector<double>
#define vtld vector<long double>
// Maps
#define mmap multimap
#define umap unordered_map
#define mii map<int, int>
#define mmii multimap<int, int>
#define umii unordered_map<int, int>
// Sets
#define mset multiset
#define uset unordered_set
#define umset unordered_multiset
// Array
#define ar array

/*
 *
 * FUNCTIONS / METHODS DEFINITIONS
 *
 */
#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SET(a, v) memset(a, v, sizeof(a))

/*
 *
 * LOOPS
 *
 */
#define F_OR(i, a, b, s)                                                       \\
  for (int i = (a); (s) > 0 ? i < (b) : i > (b); i += (s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define F(...)                                                                 \\
  F_ORC(__VA_ARGS__)                                                           \\
  (__VA_ARGS__)
#define EACH(x, a) for (auto &x : a)

/*
 *
 * MATH
 *
 */

// VARIABLES
const double PI = acos(-1);
const double Pi = 3.141592653589793;

const ll MOD = 1e9 + 7;
const ll FMOD = 998244353;

// FUNCTIONS
// Binary exponentation
ll binpow(ll a, ll b) {
  ll res = 1;
  while (b > 0) {
    res *= a * (ll)(b & 1LL);
    a *= a;
    b /= 2;
  }
  return res;
}

// Binary search
template <class T, class S> int search(T a, S el, int n = 0) {
  n = n ? n : a.size();
  int i = 0;
  for (int b = n / 2; b > 0; b /= 2)
    while (i + b < n && a[i] <= el)
      i += b;
  return i;
}

// Comparisions
template <class T> bool umin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template <class T> bool umax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

// GCD / LCM
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
int egcd(int a, int b, int &x, int &y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  int x1, y1;
  int d = egcd(b, a % b, x1, y1);
  x = y1;
  y = x1 - y1 * (a / b);
  return d;
}

/*
 *
 * INPUT / OUTPUT
 *
 */

// Reading (input)
template <class A> void read(vt<A> &v);
template <class A, size_t S> void read(ar<A, S> &a);
template <class T> void read(T &x) { cin >> x; }
void read(double &d) {
  string t;
  read(t);
  d = stod(t);
}
void read(float &d) {
  string t;
  read(t);
  d = stod(t);
}
void read(long double &d) {
  string t;
  read(t);
  d = stold(t);
}
template <class H, class... T> void read(H &h, T &...t) {
  read(h);
  read(t...);
}
template <class A> void read(vt<A> &x) {
  EACH(a, x)
  read(a);
}
template <class A, size_t S> void read(array<A, S> &x) {
  EACH(a, x)
  read(a);
}

// Type casting (for writing)
string to_string(char c) { return string(1, c); }
string to_string(bool b) { return b ? "true" : "false"; }
string to_string(const char *s) { return string(s); }
string to_string(string s) { return s; }
string to_string(vt<bool> v) {
  string res;
  F(sz(v))
  res += char('0' + v[i]);
  return res;
}

template <size_t S> string to_string(bitset<S> b) {
  string res;
  F(S)
  res += char('0' + b[i]);
  return res;
}
template <class T> string to_string(T v) {
  bool f = 1;
  string res;
  EACH(x, v) {
    if (!f)
      res += ' ';
    f = 0;
    res += to_string(x);
  }
  return res;
}

// Writing (output)
template <class A> void write(A x) { cout << to_string(x); }
template <class H, class... T> void write(const H &h, const T &...t) {
  write(h);
  write(t...);
}
// Printing (output + "\\n")
void print() { write("\\n"); }
template <class H, class... T> void print(const H &h, const T &...t) {
  write(h);
  if (sizeof...(t))
    write(' ');
  print(t...);
}

void DBG() { cerr << "]" << endl; }
template <class H, class... T> void DBG(H h, T... t) {
  cerr << to_string(h);
  if (sizeof...(t))
    cerr << ", ";
  DBG(t...);
}

#define dbg(...)                                                               \\
  cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [",           \\
      DBG(__VA_ARGS__)

/*
 *
 * CONSTANTS
 *
 */
// const int INF = 2147483647;
const int INF = 1e9;

const ll mxN = 1e9;

/*
 *
 * CODE HERE
 *
 */
void solve() {
  int n, k;
  read(n, k);
  set<pair<int, int>> s;
  F(k) {
    int l, r;
    read(l, r);
    s.insert(mp(l, r));
  }
  vt<ll> dp(n);
  dp[0] = 1;
  F(i, 1, n) {
    EACH(x, s) {
      if (x.fi <= i) {
        F(j, x.fi, x.se + 1) {
          if (j > i)
            break;
          dp[i] += dp[i - j];
          dp[i] %= FMOD;
        }
      }
    }
  }
  print(dp[n - 1]);
}

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

  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);

  int t = 1;
  // read(t);
  F(t) {
    // write("Case #",  i+1, ": ");
    solve();
  }
}

/*
 *  TEMPLATE BY LOUIS NAVARRO
 *  FREE OF USE
 *  (inspired by other templates)
 */
#include <bits/stdc++.h>

using namespace std;

/*
 *
 * TYPE DEFINITIONS
 *
 */
// Basic types
#define uint unsigned int
#define ull unsigned long long
#define ll long long
#define ld long double
// Vectors
#define vt vector
#define vti vector<int>
#define vtl vector<long long>
#define vtd vector<double>
#define vtld vector<long double>
// Maps
#define mmap multimap
#define umap unordered_map
#define mii map<int, int>
#define mmii multimap<int, int>
#define umii unordered_map<int, int>
// Sets
#define mset multiset
#define uset unordered_set
#define umset unordered_multiset
// Array
#define ar array

/*
 *
 * FUNCTIONS / METHODS DEFINITIONS
 *
 */
#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SET(a, v) memset(a, v, sizeof(a))

/*
 *
 * LOOPS
 *
 */
#define F_OR(i, a, b, s)                                                       \\
  for (int i = (a); (s) > 0 ? i < (b) : i > (b); i += (s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define F(...)                                                                 \\
  F_ORC(__VA_ARGS__)                                                           \\
  (__VA_ARGS__)
#define EACH(x, a) for (auto &x : a)

/*
 *
 * MATH
 *
 */

// VARIABLES
const double PI = acos(-1);
const double Pi = 3.141592653589793;

const ll MOD = 1e9 + 7;
const ll FMOD = 998244353;

// FUNCTIONS
// Binary exponentation
ll binpow(ll a, ll b) {
  ll res = 1;
  while (b > 0) {
    res *= a * (ll)(b & 1LL);
    a *= a;
    b /= 2;
  }
  return res;
}

// Binary search
template <class T, class S> int search(T a, S el, int n = 0) {
  n = n ? n : a.size();
  int i = 0;
  for (int b = n / 2; b > 0; b /= 2)
    while (i + b < n && a[i] <= el)
      i += b;
  return i;
}

// Comparisions
template <class T> bool umin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template <class T> bool umax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

// GCD / LCM
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
int egcd(int a, int b, int &x, int &y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  int x1, y1;
  int d = egcd(b, a % b, x1, y1);
  x = y1;
  y = x1 - y1 * (a / b);
  return d;
}

/*
 *
 * INPUT / OUTPUT
 *
 */

// Reading (input)
template <class A> void read(vt<A> &v);
template <class A, size_t S> void read(ar<A, S> &a);
template <class T> void read(T &x) { cin >> x; }
void read(double &d) {
  string t;
  read(t);
  d = stod(t);
}
void read(float &d) {
  string t;
  read(t);
  d = stod(t);
}
void read(long double &d) {
  string t;
  read(t);
  d = stold(t);
}
template <class H, class... T> void read(H &h, T &...t) {
  read(h);
  read(t...);
}
template <class A> void read(vt<A> &x) {
  EACH(a, x)
  read(a);
}
template <class A, size_t S> void read(array<A, S> &x) {
  EACH(a, x)
  read(a);
}

// Type casting (for writing)
string to_string(char c) { return string(1, c); }
string to_string(bool b) { return b ? "true" : "false"; }
string to_string(const char *s) { return string(s); }
string to_string(string s) { return s; }
string to_string(vt<bool> v) {
  string res;
  F(sz(v))
  res += char('0' + v[i]);
  return res;
}

template <size_t S> string to_string(bitset<S> b) {
  string res;
  F(S)
  res += char('0' + b[i]);
  return res;
}
template <class T> string to_string(T v) {
  bool f = 1;
  string res;
  EACH(x, v) {
    if (!f)
      res += ' ';
    f = 0;
    res += to_string(x);
  }
  return res;
}

// Writing (output)
template <class A> void write(A x) { cout << to_string(x); }
template <class H, class... T> void write(const H &h, const T &...t) {
  write(h);
  write(t...);
}
// Printing (output + "\\n")
void print() { write("\\n"); }
template <class H, class... T> void print(const H &h, const T &...t) {
  write(h);
  if (sizeof...(t))
    write(' ');
  print(t...);
}

void DBG() { cerr << "]" << endl; }
template <class H, class... T> void DBG(H h, T... t) {
  cerr << to_string(h);
  if (sizeof...(t))
    cerr << ", ";
  DBG(t...);
}

#define dbg(...)                                                               \\
  cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [",           \\
      DBG(__VA_ARGS__)

/*
 *
 * CONSTANTS
 *
 */
// const int INF = 2147483647;
const int INF = 1e9;

const ll mxN = 1e9;

/*
 *
 * CODE HERE
 *
 */
void solve() {
  int n, k;
  read(n, k);
  set<pair<int, int>> s;
  F(k) {
    int l, r;
    read(l, r);
    s.insert(mp(l, r));
  }
  vt<ll> dp(n), ps(n);
  dp[0] = ps[0] = 1;
  F(i, 1, n) {
    EACH(x, s) {
      if (x.fi <= i) {
        // F(j, x.fi, x.se+1){
        // if (j>i) break;
        // dp[i]+=dp[i-j];
        // dp[i]%=FMOD;
        //}
        dp[i] += ps[i - x.fi];
        if (x.se < i)
          dp[i] -= ps[i - x.se - 1];
        dp[i] %= FMOD;
      }
    }
    ps[i] = ps[i - 1] + dp[i];
  }
  // dbg(dp);
  print(dp[n - 1]);
}

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

  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);

  int t = 1;
  // read(t);
  F(t) {
    // write("Case #",  i+1, ": ");
    solve();
  }
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dp[200005];
const ll mod = 998244353;
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  set<int> s;
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    for (int j = x; j <= y; j++) {
      s.insert(j);
    }
  }
  dp[1] = 1;
  for (int i = 1; i <= n; i++) {
    if (dp[i]) {
      for (set<int>::iterator its = s.begin(); its != s.end(); its++) {
        int k = *its;
        if (i + k > n) {
          break;
        }
        dp[i + k] += dp[i];
        dp[i + k] %= mod;
      }
    }
  }
  printf("%lld\\n", dp[n]);
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 998244353;
struct qu {
  ll l;
  ll r;
} q[11];
struct tree {
  ll l;
  ll r;
  ll lazy;
  ll ans;
} t[4 * 200005];
void build(ll l, ll r, int pos) {
  t[pos].l = l;
  t[pos].r = r;
  if (l == r) {
    if (l == 1) {
      t[pos].ans = 1;
    }
    return;
  }
  ll mid = (l + r) / 2;
  build(l, mid, pos * 2);
  build(mid + 1, r, pos * 2 + 1);
}
void pushdown(int pos) {
  if (t[pos].lazy) {
    ll k = t[pos].lazy;
    t[pos * 2 + 1].lazy += k;
    t[pos * 2].lazy += k;
    t[pos * 2].ans += (t[pos * 2].r - t[pos * 2].l + 1) * k;
    t[pos * 2 + 1].ans += (t[pos * 2 + 1].r - t[pos * 2 + 1].l + 1) * k;
    t[pos].lazy = 0;
  }
}
void update(ll l, ll r, int pos, ll k) {
  if (l <= t[pos].l && t[pos].r <= r) {
    t[pos].ans += k * (t[pos].r - t[pos].l + 1);
    t[pos].ans %= mod;
    t[pos].lazy += k;
    return;
  }
  pushdown(pos);
  ll mid = (t[pos].l + t[pos].r) / 2;
  if (l <= mid) {
    update(l, r, pos * 2, k);
  }
  if (r > mid) {
    update(l, r, pos * 2 + 1, k);
  }
}
ll ask(ll l, ll r, int pos) {
  if (l <= t[pos].l && t[pos].r <= r) {
    return t[pos].ans;
  }
  pushdown(pos);
  ll res = 0;
  ll mid = (t[pos].l + t[pos].r) / 2;
  if (l <= mid) {
    res += ask(l, r, pos * 2);
  }
  if (r > mid) {
    res += ask(l, r, pos * 2 + 1);
  }
  return res % mod;
}
int main() {
  ll n;
  int m;
  scanf("%lld%d", &n, &m);
  set<int> s;
  for (int i = 1; i <= m; i++) {
    scanf("%lld%lld", &q[i].l, &q[i].r);
  }
  build(1, n, 1);
  for (int i = 1; i <= n; i++) {
    ll tp = ask(i, i, 1);
    if (tp) {
      for (int j = 1; j <= m; j++) {
        if (i + q[j].l > n) {
          continue;
        }
        update(i + q[j].l, min(n, i + q[j].r), 1, tp);
      }
    }
  }
  printf("%lld\\n", ask(n, n, 1));
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1E5 + 5;
const int mod = 998244353;

int dp[N];

int32_t main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  int n, k;
  cin >> n >> k;
  vector<int> idx;

  for (int i = 0; i < k; i++) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++)
      idx.push_back(j);
  }
  sort(idx.begin(), idx.end());
  idx.erase(unique(idx.begin(), idx.end()), idx.end());
  dp[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j : idx) {
      if (i - j >= 1) {
        dp[i] += dp[i - j];
        dp[i] %= mod;
      } else
        break;
    }
  }

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

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2E5 + 5;
const int mod = 998244353;

int dp[N];

void solve() {

  int n, k;
  scanf("%lld %lld", &n, &k);
  pair<int, int> p[15];

  for (int i = 0; i < k; i++) {
    int x, y;
    scanf("%lld %lld", &x, &y);
    p[i] = make_pair(x, y);
  }

  dp[1] = 1;

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

    dp[i] = 0;

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

      int l = max(1LL, i - p[j].second);
      int r = i - p[j].first;

      if (l <= r) {
        dp[i] += dp[r] - dp[l - 1];
        dp[i] %= mod;
        dp[i] += mod;
        dp[i] %= mod;
      }
    }

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

  printf("%lld\\n", ((dp[n] - dp[n - 1]) + mod) % mod);
}

int32_t main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  solve();

  return 0;
}

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


#include <bits/stdc++.h>
#define sf1(n) scanf("%d", &n)
#define sf2(n, q) scanf("%d %d", &n, &q)
#define f first
#define ss second
#define pb push_back
#define lli long long
#define mem(ar, false) memset(ar, false, sizeof(ar))
#define mpr make_pair
#define endl "\\n"
#define mod 1000000007
#define inf 9000000000000000000LL
#define M 200005

using namespace std;

int dp[200005];
int br[200005];
int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, k;
  cin >> n >> k;

  vector<int> v;
  for (int i = 1; i <= k; i++) {
    int a, b;
    cin >> a >> b;
    br[a]++;
    br[b + 1]--;
  }
  for (int i = 1; i <= n; i++) {
    br[i] += br[i - 1];
    if (br[i] == 0)
      continue;
    else
      v.pb(i);
  }
  sort(v.begin(), v.end());
  dp[1] = 1;

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

#include <bits/stdc++.h>
#define sf1(n) scanf("%d", &n)
#define sf2(n, q) scanf("%d %d", &n, &q)
#define f first
#define ss second
#define pb push_back
#define lli long long
#define mem(ar, false) memset(ar, false, sizeof(ar))
#define mpr make_pair
#define endl "\\n"
#define mod 1000000007
#define inf 9000000000000000000LL
#define M 200005

using namespace std;

lli dp[200005];
lli ar[200005];
int main() {

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

  int n, k;
  cin >> n >> k;
  vector<pair<int, int>> v;
  for (int i = 1; i <= k; i++) {
    int a, b;
    cin >> a >> b;
    v.pb(mpr(a, b));
  }
  sort(v.begin(), v.end());
  dp[1] = 1;

  ar[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < k; j++) {
      int l = i - v[j].ss;
      int r = i - v[j].f;
      if (r <= 0)
        continue;
      l = max(1, l);
      dp[i] += ar[r] - ar[l - 1];
      dp[i] %= 998244353;
    }

    ar[i] = ar[i - 1] + dp[i];
  }
  cout << dp[n] << endl;
  return 0;
}


#include "bits/stdc++.h"

#define ll long long int
#define ld long double
#define fastIO                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(nullptr)
#define pb push_back

using namespace std;
typedef pair<int, int> pii;

#define MOD 998244353

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

  ll a[n + 1];
  bool has[n + 1];
  memset(has, false, sizeof(has));
  memset(a, 0, sizeof(a));
  a[1] = 1;
  set<int> h;
  for (int i = 0; i < k; i++) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++) {
      has[j] = true;
      h.insert(j);
    }
  }

  for (int i = 1; i <= n; i++) {
    for (int j : h) {
      if (i + j > n)
        break;
      a[i + j] += a[i];
      a[i + j] %= MOD;
    }
  }

  cout << a[n];
}

#include "bits/stdc++.h"

#define ll long long int
#define ld long double
#define fastIO                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(nullptr)
#define pb push_back

using namespace std;
typedef pair<int, int> pii;

#define MOD 998244353

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

  ll a[n + 1];
  ll pref[n + 1];
  memset(pref, 0, sizeof(pref));
  memset(a, 0, sizeof(a));
  a[1] = pref[1] = 1;
  vector<pii> segments(k);
  for (int i = 0; i < k; i++) {
    int l, r;
    cin >> l >> r;
    segments[i] = {l, r};
  }

  for (int i = 2; i <= n; i++) {
    for (pii seg : segments) {
      int l = max(0, i - seg.second - 1);
      int r = max(0, i - seg.first);
      a[i] += ((pref[r] - pref[l]) + MOD) % MOD;
      a[i] %= MOD;
    }
    pref[i] = ((pref[i - 1] % MOD) + (a[i] % MOD)) % MOD;
  }

  cout << a[n];
}


#include <bits/stdc++.h>

using namespace std;

void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\\'' << x << '\\''; }
void __print(const char *x) { cerr << '\\"' << x << '\\"'; }
void __print(const string &x) { cerr << '\\"' << x << '\\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }

template <typename T, typename V> void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T> void __print(const T &x) {
  int f = 0;
  cerr << '{';
  for (auto &i : x)
    cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\\n"; }
template <typename T, typename... V> void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v))
    cerr << ", ";
  _print(v...);
}
#ifndef ONLINE_JUDGE
#define debug(x...)                                                            \\
  cerr << "[" << #x << "] = [";                                                \\
  _print(x)
#else
#define debug(x...)
#endif
const long long INF = 1e18;
int md = 998244353;
int dfs(int index, set<int> &s, int n, vector<int> &dp) {
  if (index == n)
    return 1;
  if (dp[index] != -1)
    return dp[index];
  long long ans = 0LL;
  for (auto i : s) {
    if (i + index <= n) {
      ans = (ans % md + dfs(i + index, s, n, dp) % md) % md;
    }
  }
  return dp[index] = ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, k;
  cin >> n >> k;
  vector<int> pre(n + 2);
  for (int i = 0; i < k; i++) {
    int l, r;
    cin >> l >> r;
    pre[l]++;
    pre[r + 1]--;
  }
  // debug(pre);
  for (int i = 1; i <= n; i++) {
    pre[i] += pre[i - 1];
  }
  // debug(pre);
  set<int> s;
  for (int i = 1; i <= n; i++) {
    if (pre[i] >= 1)
      s.insert(i);
  }

  vector<int> dp(n + 1, -1);
  int ans = dfs(1, s, n, dp);
  // debug(dp);
  cout << ans;
  return 0;
}
// https://www.youtube.com/watch?v=ZQqccia8bVo

#include <bits/stdc++.h>

using namespace std;

void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\\'' << x << '\\''; }
void __print(const char *x) { cerr << '\\"' << x << '\\"'; }
void __print(const string &x) { cerr << '\\"' << x << '\\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }

template <typename T, typename V> void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T> void __print(const T &x) {
  int f = 0;
  cerr << '{';
  for (auto &i : x)
    cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\\n"; }
template <typename T, typename... V> void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v))
    cerr << ", ";
  _print(v...);
}
#ifndef ONLINE_JUDGE
#define debug(x...)                                                            \\
  cerr << "[" << #x << "] = [";                                                \\
  _print(x)
#else
#define debug(x...)
#endif
const long long INF = 1e18;
int md = 998244353;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, k;
  cin >> n >> k;
  vector<int> dp(n + 3);
  vector<int> pre(n + 3);
  vector<int> l(k);
  vector<int> r(k);
  for (int i = 0; i < k; i++) {
    cin >> l[i];
    cin >> r[i];
  }
  dp[1] = 1;
  pre[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < k; j++) {
      if (l[j] >= i)
        continue;
      int left = l[j];
      int right = min(i - 1, r[j]);
      int val = (pre[i - left] - pre[i - right - 1] + md) % md;
      dp[i] = (dp[i] + val) % md;
    }
    pre[i] = (pre[i - 1] % md + dp[i] % md) % md;
  }
  cout << dp[n];
  return 0;
}
// https://www.youtube.com/watch?v=ZQqccia8bVo


#include <bits/stdc++.h>
// #include<atcoder/all>

using namespace std;
// using namespace atcoder;

int main() {
  int n, k2;
  cin >> n >> k2;
  set<int> s;
  int dp[n];
  for (int i = 0; i < n; i++) {
    dp[i] = 0;
  }
  dp[0] = 1;
  int l[k2], r[k2];
  for (int i = 0; i < k2; i++) {
    cin >> l[i] >> r[i];
    for (int j = l[i]; j <= r[i]; j++) {
      s.insert(j);
    }
  }

  for (int k = 0; k < n; k++) {
    auto idx = s.begin();
    while (idx != s.end()) {
      int j = *idx;
      if (k + j >= n)
        break;
      if (dp[k] != 0) {
        dp[k + j] += dp[k];
        dp[k + j] %= 998244353;
      }
      idx++;
    }
  }
  cout << dp[n - 1] << endl;
}

#include <bits/stdc++.h>
// #include<atcoder/all>

using namespace std;
// using namespace atcoder;

// https://algo-logic.info/segment-tree/

/* SegTreeLazyProportional<X,M>(n,fx,fa,fm,fp,ex,em): モノイド(集合X,
   二項演算fx,fa,fm,p 単位元ex,em)についてサイズnで構築 set(int i, X x),
   build(): i番目の要素をxにセット。まとめてセグ木を構築する。O(n) update(i,x):
   i 番目の要素を x に更新。O(log(n)) query(a,b):  [a,b)
   全てにfxを作用させた値を取得。O(log(n))
*/
template <typename X, typename M> struct SegTreeLazyProportional {
  using FX = function<X(X, X)>;
  using FA = function<X(X, M)>;
  using FM = function<M(M, M)>;
  using FP = function<M(M, int)>;
  int n;
  FX fx;
  FA fa;
  FM fm;
  FP fp;
  const X ex;
  const M em;
  vector<X> dat;
  vector<M> lazy;
  SegTreeLazyProportional(int n_, FX fx_, FA fa_, FM fm_, FP fp_, X ex_, M em_)
      : n(), fx(fx_), fa(fa_), fm(fm_), fp(fp_), ex(ex_), em(em_),
        dat(n_ * 4, ex), lazy(n_ * 4, em) {
    int x = 1;
    while (n_ > x)
      x *= 2;
    n = x;
  }
  void set(int i, X x) { dat[i + n - 1] = x; }
  void build() {
    for (int k = n - 2; k >= 0; k--)
      dat[k] = fx(dat[2 * k + 1], dat[2 * k + 2]);
  }
  /* lazy eval */
  void eval(int k, int len) {
    if (lazy[k] == em)
      return;        // 更新するものが無ければ終了
    if (k < n - 1) { // 葉でなければ子に伝搬
      lazy[k * 2 + 1] = fm(lazy[k * 2 + 1], lazy[k]);
      lazy[k * 2 + 2] = fm(lazy[k * 2 + 2], lazy[k]);
    }
    // 自身を更新
    dat[k] = fa(dat[k], fp(lazy[k], len));
    lazy[k] = em;
  }
  void update(int a, int b, M x, int k, int l, int r) {
    eval(k, r - l);
    if (a <= l && r <= b) { // 完全に内側の時
      lazy[k] = fm(lazy[k], x);
      eval(k, r - l);
    } else if (a < r && l < b) {                  // 一部区間が被る時
      update(a, b, x, k * 2 + 1, l, (l + r) / 2); // 左の子
      update(a, b, x, k * 2 + 2, (l + r) / 2, r); // 右の子
      dat[k] = fx(dat[k * 2 + 1], dat[k * 2 + 2]);
    }
  }
  void update(int a, int b, M x) { update(a, b, x, 0, 0, n); }
  X query_sub(int a, int b, int k, int l, int r) {
    eval(k, r - l);
    if (r <= a || b <= l) { // 完全に外側の時
      return ex;
    } else if (a <= l && r <= b) { // 完全に内側の時
      return dat[k];
    } else { // 一部区間が被る時
      X vl = query_sub(a, b, k * 2 + 1, l, (l + r) / 2);
      X vr = query_sub(a, b, k * 2 + 2, (l + r) / 2, r);
      return fx(vl, vr);
    }
  }
  X query(int a, int b) { return query_sub(a, b, 0, 0, n); }
};

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

  using X = long long;
  using M = long long;
  auto fx = [](X x1, X x2) -> X { return (x1 + x2) % 998244353; };
  auto fa = [](X x, M m) -> X { return (x + m) % 998244353; };
  auto fm = [](M m1, M m2) -> M { return (m1 + m2) % 998244353; };
  auto fp = [](M m, long long n) -> M { return (m * n) % 998244353; };
  long long ex = 0;
  long long em = 0;
  SegTreeLazyProportional<X, M> rmq(n, fx, fa, fm, fp, ex, em);

  for (int i = 0; i < n; i++) {
    rmq.set(i, 0);
  }

  rmq.set(0, 1);

  int l[k], r[k];
  for (int i = 0; i < k; i++) {
    cin >> l[i] >> r[i];
  }
  for (int j = 0; j < n; j++) {
    for (int m = 0; m < k; m++) {
      int l2 = l[m] + j;
      if (l2 >= n)
        continue;
      int r2 = r[m] + j;
      if (r2 >= n)
        r2 = n - 1;
      int nn = rmq.query(j, j + 1);
      if (nn != 0) {
        rmq.update(l2, r2 + 1, nn);
      }
    }
  }

  cout << rmq.query(n - 1, n) << endl;
}


//
//  main.cpp
//  AtCoderD
//
//  Created by Shivam on 19/09/20.
//  Copyright © 2020 Shivam. All rights reserved.
//

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
#define x first
#define y second
#define mp make_pair
#define endl "\\n"
typedef long long ll;
int mod = 998244353;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, k;
  cin >> n >> k;
  vector<pair<int, int>> intervals(k);
  for (int i = 0; i < k; ++i)
    cin >> intervals[i].x >> intervals[i].y;
  sort(intervals.begin(), intervals.end());
  vector<ll> dp(n + 1, 0);
  dp[n] = 1;
  for (int i = n - 1; i >= 1; --i) {
    for (auto Int : intervals) {
      if (Int.x > n - i)
        break;
      int m = min(n - i, Int.y);
      for (int j = Int.x; j <= m; ++j) {
        dp[i] += dp[i + j];
        if (dp[i] >= mod)
          dp[i] -= mod;
      }
    }
    // cout<<i<<" "<<dp[i]<<endl;
  }
  cout << dp[1] << endl;
  return 0;
}

//
//  main.cpp
//  AtCoderD
//
//  Created by Shivam on 19/09/20.
//  Copyright © 2020 Shivam. All rights reserved.
//

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
#define x first
#define y second
#define mp make_pair
#define endl "\\n"
typedef long long ll;
int mod = 998244353;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, k;
  cin >> n >> k;
  vector<pair<int, int>> intervals(k);
  for (int i = 0; i < k; ++i)
    cin >> intervals[i].x >> intervals[i].y;
  sort(intervals.begin(), intervals.end());
  vector<ll> dp(n + 1, 0), suffix(n + 1, 0);
  dp[n - 1] = 1;
  suffix[n - 1] = 1;
  for (int i = n - 2; i >= 0; --i) {
    for (auto range : intervals) {
      if (i + range.x > n - 1)
        break;
      int m = min(range.y, n - 1 - i);
      dp[i] += suffix[i + range.x] - suffix[i + m + 1] + mod;
      if (dp[i] >= mod)
        dp[i] %= mod;
    }
    suffix[i] = dp[i] + suffix[i + 1];
    if (suffix[i] >= mod)
      suffix[i] %= mod;
    // cout<<i<<" "<<dp[i]<<" "<<suffix[i]<<endl;
  }
  cout << dp[0] << endl;
  return 0;
}


/*@author Vipen Loka*/
#include <bits/stdc++.h>
#define endl '\\n'
#define ff first
#define ss second
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vi>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define deb(x) cout << #x << ':' << x << '\\n';

using namespace std;

void solve() {
  int i, j;
  int n, k;
  cin >> n >> k;
  vector<int> pos(n + 1, 0), dp(n + 1, 0);
  vector<pair<int, int>> intervals(k);

  for (int i = 0; i < k; ++i) {
    int a, b;
    // cin >> a >> b;
    cin >> intervals[i].ff >> intervals[i].ss;
    // printf("%d %d\\n",intervals[i].ff,intervals[i].ss);
    // for (int j = a; j <= b; ++j)
    // {
    // 	pos[j]=1;
    // }
  }
  dp[1] = 1;
  sort(intervals.begin(), intervals.end());

  for (int i = 2; i <= n; ++i) {
    for (int t = 0; t < k; t++) {
      // printf("%d %d\\n",intervals[t].ff,intervals[t].ss);
      for (int j = intervals[t].ff; j <= min(intervals[t].ss, i - 1); ++j) {
        dp[i] += dp[i - j];
        dp[i] %= 998244353;
      }
    }

    // printf("%d\\n",dp[i]);
  }

  printf("%d\\n", dp[n]);
}

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

  int T = 1;
  // cin >> T;
  while (T--) {
    solve();
  }
}

/*@author Vipen Loka*/
#include <bits/stdc++.h>
#define endl '\\n'
#define ff first
#define ss second
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vi>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define mod 998244353
#define inf 1000000000000000001;
#define deb(x) cout << #x << ':' << x << '\\n';

using namespace std;

struct fentree {
  int n;
  vector<ll> tree;

  void init(int n) {
    this->n = n;
    tree.assign(n + 2, 0);
  }

  void set(int i, ll val) {
    while (i <= n) {
      tree[i] += val;
      tree[i] %= mod;
      i += i & -i;
    }
  }

  ll get(int a) {
    ll s = 0;
    while (a > 0) {
      s += tree[a];
      s %= mod;
      a -= a & -a;
    }

    return s;
  }

  ll get(int a, int b) {
    // a and b are inclusive
    ll t = get(b) - get(a - 1);
    if (t < 0)
      t += mod;
    return t;
  }
};

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

  vector<pair<int, int>> intervals(k);
  for (int i = 0; i < k; ++i) {
    cin >> intervals[i].ff >> intervals[i].ss;
  }

  fentree t;
  t.init(n);
  t.set(1, 1);

  for (int i = 2; i <= n; ++i) {
    ll s = 0;
    for (int j = 0; j < k; ++j) {
      int a = max(0, i - intervals[j].ss);
      int b = min(i - 1, i - intervals[j].ff);

      s += t.get(a, b);
      s %= mod;
    }

    t.set(i, s);
  }

  printf("%lld\\n", t.get(n, n) % mod);
}

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

  int T = 1;
  // cin >> T;
  while (T--) {
    solve();
  }
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using indexed_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define sim template <class c
#define ris return *this
#define dor > debug &operator<<
#define eni(x)                                                                 \\
  sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<(    \\
            c i) {
sim > struct rge {
  c b, e;
};
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifndef LOCAL
  ~debug() { cerr << endl; }
  eni(!=) cerr << boolalpha << i;
  ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
  sim dor(const c &) { ris; }
#endif
}
;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define int long long
#define ld long double
#define pb push_back
#define mp make_pair
#define in insert
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define sz(v) (int)(v.size())
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define mem(a, s) memset(a, s, sizeof(a))
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define repr(i, a, b) for (int i = a; i >= b; --i)
typedef vector<int> vi;
typedef stack<int> sti;
typedef queue<int> qi;
typedef pair<int, int> pii;
typedef set<int> si;
typedef map<int, int> mii;
typedef vector<pii> vpi;
int _x[] = {0, 0, -1, 1, -1, 1, -1, 1};
int _y[] = {-1, 1, 0, 0, 1, -1, -1, 1};
void solve();
void pre();
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  pre();
  int t = 1;
  // cin >> t;
  rep(i, 1, t) {
    // cout << "Case # " << i << ": ";
    solve();
  }
  return 0;
}
const int mod = 998244353;
void pre() {}
void solve() {
  int n, k;
  cin >> n >> k;
  unordered_set<int> s;
  int x, y;
  rep(i, 1, k) {
    cin >> x >> y;
    rep(i, x, y) s.in(i);
    // s.in(y);
  }
  int dp[n + 1];
  dp[1] = 1;
  rep(i, 2, n) {
    dp[i] = 0;
    for (auto x : s) {
      if (i - x > 0) {
        dp[i] = (dp[i] % mod + dp[i - x] % mod) % mod;
      }
    }
  }
  cout << dp[n];
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using indexed_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define int long long
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define in insert
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define sz(v) (int)(v.size())
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define mem(a, s) memset(a, s, sizeof(a))
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define repr(i, a, b) for (int i = a; i >= b; --i)
#define MAX 8000000000000000064LL
#define MIN -8000000000000000064LL
typedef vector<int> vi;
typedef stack<int> sti;
typedef queue<int> qi;
typedef pair<int, int> pii;
typedef set<int> si;
typedef map<int, int> mii;
typedef vector<pii> vpi;
const int mod = 998244353;
ll add(ll a, ll b) { return (a % mod + b % mod + ((MAX) / mod) * mod) % mod; }
ll sub(ll a, ll b) { return (a % mod - b % mod + ((MAX) / mod) * mod) % mod; }
ll mul(ll a, ll b) {
  return ((a % mod) * (b % mod) + ((MAX) / mod) * mod) % mod;
}
ll lcm(ll a, ll b) { return (a * b) / __gcd(a, b); }
ll fact[1000007] = {0};
ll expo(ll x, ll y) {
  ll res = 1;
  x = x % mod;
  while (y > 0) {
    if (y & 1)
      res = (1ll * res * x) % mod;
    y = y >> 1;
    x = (1ll * x * x) % mod;
  }
  return res;
}
void facto() {
  fact[0] = 1;
  fact[1] = 1;
  for (ll i = 2; i < 1000007; i++)
    fact[i] = (fact[i - 1] * i) % mod;
}
ll ncr(ll n, ll r) {
  ll res = 1;
  res = fact[n];
  res = (res * (expo(fact[r], mod - 2))) % mod;
  res = (res * (expo(fact[n - r], mod - 2))) % mod;
  return res;
}
ll npr(ll n, ll r) {
  facto();
  ll res = 1;
  res = fact[n];
  res = (res * (expo(fact[n - r], mod - 2))) % mod;
  return res;
}
int _x[] = {0, 0, -1, 1, -1, 1, -1, 1};
int _y[] = {-1, 1, 0, 0, 1, -1, -1, 1};
void solve();
void pre();
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  pre();
  int t = 1;
  // cin >> t;
  rep(i, 1, t) { solve(); }
  return 0;
}
void pre() {}
void solve() {
  int n, k;
  cin >> n >> k;
  int l[k], r[k];
  rep(i, 0, k - 1) { cin >> l[i] >> r[i]; }
  int dp[n + 1];
  mem(dp, 0);
  dp[0] = 0, dp[1] = 1;
  rep(i, 2, n) {
    rep(j, 0, k - 1) {
      if ((i - l[j]) >= 1) {
        dp[i] = add(dp[i], dp[i - l[j]]);
        dp[i] = sub(dp[i], dp[max(0LL, i - r[j] - 1)]);
      }
    }
    if (i == n) {
      cout << dp[n] << " ";
      return;
    }
    dp[i] = add(dp[i], dp[i - 1]);
  }
}