#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 998244353;
int pos[100010], sum[100010], dp[100010];
pair<int, int> a[15];
signed main() {
  int n, k, i, j, p;
  cin >> n >> k;
  for (i = 1; i <= k; i++) {
    cin >> a[i].first >> a[i].second;
    for (j = a[i].first; j <= a[i].second; j++)
      pos[j] = i;
  }
  sort(a + 1, a + k + 1);
  dp[1] = 1;
  if (pos[1])
    sum[pos[1]] = (sum[pos[1]] + dp[1]) % mod;
  for (i = 2; i <= n; i++) {
    for (j = 1; j <= k; j++)
      dp[i] = (dp[i] + sum[j]) % mod;
    if (pos[i])
      sum[pos[i]] = (sum[pos[i]] + dp[i]) % mod;
  }
  cout << dp[n];
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 998244353;
int sum[200010], dp[200010];
pair<int, int> a[15];
signed main() {
  int n, k, i, j;
  cin >> n >> k;
  for (i = 1; i <= k; i++)
    cin >> a[i].first >> a[i].second;
  sort(a + 1, a + k + 1);
  dp[1] = 1;
  for (i = 2; i <= n; i++) {
    for (j = 1; j <= k; j++)
      sum[j] = (sum[j] + mod + mod - dp[max(0ll, i - a[j].second - 1)] +
                dp[max(0ll, i - a[j].first)]) %
               mod;
    for (j = 1; j <= k; j++)
      dp[i] = (dp[i] + sum[j]) % mod;
  }
  cout << dp[n] % mod;
  return 0;
}


#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x)                                                                \\
  {                                                                            \\
    for (auto i : x) {                                                         \\
      cout << i << " ";                                                        \\
    }                                                                          \\
    cout << endl;                                                              \\
  }
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int MOD = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % MOD + MOD) % MOD) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a) {
    if ((x += a.x) >= MOD)
      x -= MOD;
    return *this;
  }
  mint &operator-=(const mint a) {
    if ((x += MOD - a.x) >= MOD)
      x -= MOD;
    return *this;
  }
  mint &operator*=(const mint a) {
    (x *= a.x) %= MOD;
    return *this;
  }
  mint operator+(const mint a) const { 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; }
// combination MOD prime
struct combination {
  vector<mint> fact, ifact;
  combination(int n) : fact(n + 1), ifact(n + 1) {
    assert(n < MOD);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i)
      fact[i] = fact[i - 1] * i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i)
      ifact[i - 1] = ifact[i] * i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n)
      return 0;
    return fact[n] * ifact[k] * ifact[n - k];
  }
  mint p(int n, int k) {
    if (k < 0 || k > n)
      return 0;
    return fact[n] * ifact[n - k];
  }
}; // comb(10000007);
// comb(5, 2) → 10, comb.p(5, 2) → 20
// comb.fact[4] → 24, 2のN乗 → mint(2).pow(N)

mint dp[200005];
mint imos[200005];

int main() {
  int N, K;
  cin >> N >> K;
  vector<P> LR(N);
  rep(i, K) cin >> LR[i].first >> LR[i].second;
  dp[0] = 1;
  for (int i = 0; i < N; i++) {
    if (i > 0) {
      imos[i] += imos[i - 1];
      dp[i] += imos[i];
    }
    for (auto p : LR) {
      int left = i + p.first;
      if (left >= N)
        continue;
      int right = min(N - 1, i + p.second);
      imos[left] += dp[i];
      imos[right + 1] -= dp[i];
    }
  }
  cout << dp[N - 1] << '\\n';
  return 0;
}

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x)                                                                \\
  {                                                                            \\
    for (auto i : x) {                                                         \\
      cout << i << " ";                                                        \\
    }                                                                          \\
    cout << endl;                                                              \\
  }
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int MOD = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % MOD + MOD) % MOD) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a) {
    if ((x += a.x) >= MOD)
      x -= MOD;
    return *this;
  }
  mint &operator-=(const mint a) {
    if ((x += MOD - a.x) >= MOD)
      x -= MOD;
    return *this;
  }
  mint &operator*=(const mint a) {
    (x *= a.x) %= MOD;
    return *this;
  }
  mint operator+(const mint a) const { 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; }
// combination MOD prime
struct combination {
  vector<mint> fact, ifact;
  combination(int n) : fact(n + 1), ifact(n + 1) {
    assert(n < MOD);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i)
      fact[i] = fact[i - 1] * i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i)
      ifact[i - 1] = ifact[i] * i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n)
      return 0;
    return fact[n] * ifact[k] * ifact[n - k];
  }
  mint p(int n, int k) {
    if (k < 0 || k > n)
      return 0;
    return fact[n] * ifact[n - k];
  }
}; // comb(10000007);
// comb(5, 2) → 10, comb.p(5, 2) → 20
// comb.fact[4] → 24, 2のN乗 → mint(2).pow(N)

template <typename T> struct BIT {
  int n;
  vector<T> d;
  BIT(int n = 0) : n(n), d(n + 1) {}
  void add(int i, T x = 1) {
    for (i++; i <= n; i += i & -i) {
      // i&-iで最下位bitを足している
      d[i] += x;
    }
  }
  T sum(int i) {
    T x = 0;
    for (i++; i; i -= i & -i) {
      x += d[i];
    }
    return x;
  }
  T semiopenSum(int l, int r) {
    // [l,r)の半開区間
    return sum(r - 1) - sum(l - 1);
  }
}; // BIT<int> bit(N);

mint dp[200005];

int main() {
  // dp、Kが小さい、BIT
  // L と　Rに注目
  int N, K;
  cin >> N >> K;
  vector<P> LR(K);
  rep(i, K) cin >> LR[i].first >> LR[i].second;
  BIT<mint> bit(N);
  bit.add(0);
  dp[0] = 1;
  for (int i = 1; i <= N; i++) {
    for (auto p : LR) {
      if (i - p.first < 0)
        continue;
      int left = i - p.second, right = i - p.first;
      if (left < 0)
        left = 0;
      dp[i] += bit.semiopenSum(left, right + 1);
    }
    bit.add(i, dp[i]);
  }
  cout << dp[N - 1] << '\\n';
  return 0;
}


#include <iostream>
using namespace std;

int n, k;
int l[10], r[10], a[200001];
const int M = 998244353;

int main() {

  cin >> n >> k;

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

  fill(a, a + n + 1, 0);
  a[1] = 1;

  for (int i = 1; i < n; i++) {
    for (int j = 0; j < k; j++) {
      if (i + l[j] <= n) {
        for (int k = l[j]; k <= r[j]; k++) {
          if (i + k <= n)
            a[i + k] = (a[i + k] + a[i]) % M;
        }
      }
    }
  }

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


#include <algorithm>
#include <bits/stdc++.h>
#include <cstdlib>
#include <fstream>
#include <functional>
#include <iostream>
#include <math.h>
#include <numeric>
#include <utility>
#include <vector>

#define int long long

struct edge {
  int to;
  int cost;
};

using namespace std;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vb = vector<bool>;
using qi = queue<int>;
using P = pair<int, int>;
using graph = vector<vector<edge>>;
// using graph = vector<vector<int>>;

#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define REP(i, n) for (int i = 0; i < n; i++)
#define delim(i, n) cout << (i == n - 1 ? "\\n" : " ");

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

const int inf = 1LL << 60;
// const int inf = 100000000;
const int mod = 1000000007;

const int maxn = 2e5 + 2;
int n, m, k;
vi dp(maxn);
vi num;

vi dx = {-1, 0, 0, 1};
vi dy = {0, -1, 1, 0};

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n >> k;
  REP(i, k) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++)
      num.push_back(j);
  }

  int len = (int)num.size();
  dp[0] = 1;

  REP(i, n) {
    REP(j, len) {
      if (num[j] <= i) {
        dp[i] += dp[i - num[j]];
        dp[i] %= 998244353;
      }
    }
  }

  cout << std::fixed << std::setprecision(10) << dp[n - 1] << "\\n";
}

#include <algorithm>
#include <bits/stdc++.h>
#include <cstdlib>
#include <fstream>
#include <functional>
#include <iostream>
#include <math.h>
#include <numeric>
#include <utility>
#include <vector>

#define int long long

struct edge {
  int to;
  int cost;
};

using namespace std;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vb = vector<bool>;
using qi = queue<int>;
using P = pair<int, int>;
using graph = vector<vector<edge>>;
// using graph = vector<vector<int>>;

#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define REP(i, n) for (int i = 0; i < n; i++)
#define delim(i, n) cout << (i == n - 1 ? "\\n" : " ");

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

const int inf = 1LL << 60;
// const int inf = 100000000;
const int mod = 1000000007;

const int maxn = 2e5 + 2;
int n, m, k;
vi dp(maxn);
vii num(10, vi(2));
vi nsum(10);

vi dx = {-1, 0, 0, 1};
vi dy = {0, -1, 1, 0};

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n >> k;
  REP(i, k) { cin >> num[i][0] >> num[i][1]; }

  dp[0] = 1;

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

  cout << std::fixed << std::setprecision(10) << dp[n - 1] << "\\n";
}


#include <bits/stdc++.h>
#define ll long long
#define ls id << 1
#define rs id << 1 | 1
#define mem(array, value, size, type)                                          \\
  memset(array, value, ((size) + 5) * sizeof(type))
#define memarray(array, value) memset(array, value, sizeof(array))
#define fillarray(array, value, begin, end)                                    \\
  fill((array) + (begin), (array) + (end) + 1, value)
#define fillvector(v, value) fill((v).begin(), (v).end(), value)
#define pb(x) push_back(x)
#define st(x) (1LL << (x))
#define pii pair<int, int>
#define mp(a, b) make_pair((a), (b))
#define Flush fflush(stdout)
#define vecfirst (*vec.begin())
#define veclast (*vec.rbegin())
#define vecall(v) (v).begin(), (v).end()
#define vecupsort(v) (sort((v).begin(), (v).end()))
#define vecdownsort(v, type) (sort(vecall(v), greater<type>()))
#define veccmpsort(v, cmp) (sort(vecall(v), cmp))
using namespace std;
const int N = 500050;
const int inf = 0x3f3f3f3f;
const ll llinf = 0x3f3f3f3f3f3f3f3f;
const int mod = 998244353;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0);
clock_t TIME__START, TIME__END;
void program_end() {
#ifdef ONLINE
  printf("\\n\\nTime used: %.6lf(s)\\n", ((double)TIME__END - TIME__START) / 1000);
  system("pause");
#endif
}
vector<int> S;
int n, k;
ll dp[N];

inline void solve() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= k; ++i) {
    int l, r;
    scanf("%d%d", &l, &r);
    for (int j = l; j <= r; ++j)
      S.push_back(j);
  }
  vecupsort(S);
  S.resize(unique(vecall(S)) - S.begin());
  dp[1] = 1;
  for (int i = 2; i <= n; ++i) {
    for (auto j : S) {
      if (i - j <= 0)
        break;
      dp[i] += dp[i - j], dp[i] %= mod;
    }
  }
  cout << dp[n];
}

int main() {
  TIME__START = clock();
  int Test = 1;
  // scanf("%d", &Test);
  while (Test--) {
    solve();
    // if (Test)
    //     putchar('\\n');
  }
  TIME__END = clock();
  program_end();
  return 0;
}

#include <bits/stdc++.h>
#define ll long long
#define ls id << 1
#define rs id << 1 | 1
#define mem(array, value, size, type)                                          \\
  memset(array, value, ((size) + 5) * sizeof(type))
#define memarray(array, value) memset(array, value, sizeof(array))
#define fillarray(array, value, begin, end)                                    \\
  fill((array) + (begin), (array) + (end) + 1, value)
#define fillvector(v, value) fill((v).begin(), (v).end(), value)
#define pb(x) push_back(x)
#define st(x) (1LL << (x))
#define pii pair<int, int>
#define mp(a, b) make_pair((a), (b))
#define Flush fflush(stdout)
#define vecfirst (*vec.begin())
#define veclast (*vec.rbegin())
#define vecall(v) (v).begin(), (v).end()
#define vecupsort(v) (sort((v).begin(), (v).end()))
#define vecdownsort(v, type) (sort(vecall(v), greater<type>()))
#define veccmpsort(v, cmp) (sort(vecall(v), cmp))
using namespace std;
const int N = 500050;
const int inf = 0x3f3f3f3f;
const ll llinf = 0x3f3f3f3f3f3f3f3f;
const int mod = 998244353;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0);
clock_t TIME__START, TIME__END;
void program_end() {
#ifdef ONLINE
  printf("\\n\\nTime used: %.6lf(s)\\n", ((double)TIME__END - TIME__START) / 1000);
  system("pause");
#endif
}
int n, k;
ll dp[N], sum[N];
int l[N], r[N];

inline void solve() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= k; ++i)
    scanf("%d%d", &l[i], &r[i]);
  dp[1] = sum[1] = 1;
  for (int i = 2; i <= n; ++i) {
    for (int j = 1; j <= k; ++j)
      dp[i] += (sum[max(0, i - l[j])] - sum[max(0, i - r[j] - 1)]) % mod,
          dp[i] %= mod, dp[i] += mod, dp[i] %= mod;
    sum[i] = (sum[i - 1] + dp[i]) % mod;
  }
  cout << dp[n];
}

int main() {
  TIME__START = clock();
  int Test = 1;
  // scanf("%d", &Test);
  while (Test--) {
    solve();
    // if (Test)
    //     putchar('\\n');
  }
  TIME__END = clock();
  program_end();
  return 0;
}


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

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template <class T1, class T2> ostream &operator<<(ostream &s, pair<T1, T2> P) {
  return s << '<' << P.first << ", " << P.second << '>';
}
template <class T> ostream &operator<<(ostream &s, vector<T> P) {
  for (int i = 0; i < P.size(); ++i) {
    if (i > 0) {
      s << " ";
    }
    s << P[i];
  }
  return s;
}
template <class T> ostream &operator<<(ostream &s, vector<vector<T>> P) {
  for (int i = 0; i < P.size(); ++i) {
    s << endl << P[i];
  }
  return s << endl;
}
template <class T> ostream &operator<<(ostream &s, set<T> P) {
  for (auto it : P) {
    s << "<" << it << "> ";
  }
  return s << endl;
}
template <class T1, class T2> ostream &operator<<(ostream &s, map<T1, T2> P) {
  for (auto it : P) {
    s << "<" << it.first << "->" << it.second << "> ";
  }
  return s << endl;
}

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

namespace NTT {
long long modpow(long long a, long long n, int mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

long long modinv(long long a, int mod) {
  long long b = mod, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b, swap(a, b);
    u -= t * v, swap(u, v);
  }
  u %= mod;
  if (u < 0)
    u += mod;
  return u;
}

int calc_primitive_root(int mod) {
  if (mod == 2)
    return 1;
  if (mod == 167772161)
    return 3;
  if (mod == 469762049)
    return 3;
  if (mod == 754974721)
    return 11;
  if (mod == 998244353)
    return 3;
  int divs[20] = {};
  divs[0] = 2;
  int cnt = 1;
  long long x = (mod - 1) / 2;
  while (x % 2 == 0)
    x /= 2;
  for (long long i = 3; i * i <= x; i += 2) {
    if (x % i == 0) {
      divs[cnt++] = i;
      while (x % i == 0)
        x /= i;
    }
  }
  if (x > 1)
    divs[cnt++] = x;
  for (int g = 2;; g++) {
    bool ok = true;
    for (int i = 0; i < cnt; i++) {
      if (modpow(g, (mod - 1) / divs[i], mod) == 1) {
        ok = false;
        break;
      }
    }
    if (ok)
      return g;
  }
}

int get_fft_size(int N, int M) {
  int size_a = 1, size_b = 1;
  while (size_a < N)
    size_a <<= 1;
  while (size_b < M)
    size_b <<= 1;
  return max(size_a, size_b) << 1;
}

// number-theoretic transform
template <class mint> void trans(vector<mint> &v, bool inv = false) {
  if (v.empty())
    return;
  int N = (int)v.size();
  int MOD = v[0].getmod();
  int PR = calc_primitive_root(MOD);
  static bool first = true;
  static vector<long long> vbw(30), vibw(30);
  if (first) {
    first = false;
    for (int k = 0; k < 30; ++k) {
      vbw[k] = modpow(PR, (MOD - 1) >> (k + 1), MOD);
      vibw[k] = modinv(vbw[k], MOD);
    }
  }
  for (int i = 0, j = 1; j < N - 1; j++) {
    for (int k = N >> 1; k > (i ^= k); k >>= 1)
      ;
    if (i > j)
      swap(v[i], v[j]);
  }
  for (int k = 0, t = 2; t <= N; ++k, t <<= 1) {
    long long bw = vbw[k];
    if (inv)
      bw = vibw[k];
    for (int i = 0; i < N; i += t) {
      mint w = 1;
      for (int j = 0; j < t / 2; ++j) {
        int j1 = i + j, j2 = i + j + t / 2;
        mint c1 = v[j1], c2 = v[j2] * w;
        v[j1] = c1 + c2;
        v[j2] = c1 - c2;
        w *= bw;
      }
    }
  }
  if (inv) {
    long long invN = modinv(N, MOD);
    for (int i = 0; i < N; ++i)
      v[i] = v[i] * invN;
  }
}

// for garner
static constexpr int MOD0 = 754974721;
static constexpr int MOD1 = 167772161;
static constexpr int MOD2 = 469762049;
using mint0 = Fp<MOD0>;
using mint1 = Fp<MOD1>;
using mint2 = Fp<MOD2>;
static const mint1 imod0 = 95869806;   // modinv(MOD0, MOD1);
static const mint2 imod1 = 104391568;  // modinv(MOD1, MOD2);
static const mint2 imod01 = 187290749; // imod1 / MOD0;

// small case (T = mint, long long)
template <class T> vector<T> naive_mul(const vector<T> &A, const vector<T> &B) {
  if (A.empty() || B.empty())
    return {};
  int N = (int)A.size(), M = (int)B.size();
  vector<T> res(N + M - 1);
  for (int i = 0; i < N; ++i)
    for (int j = 0; j < M; ++j)
      res[i + j] += A[i] * B[j];
  return res;
}

// mint
template <class mint>
vector<mint> mul(const vector<mint> &A, const vector<mint> &B) {
  if (A.empty() || B.empty())
    return {};
  int N = (int)A.size(), M = (int)B.size();
  if (min(N, M) < 30)
    return naive_mul(A, B);
  int MOD = A[0].getmod();
  int size_fft = get_fft_size(N, M);
  if (MOD == 998244353) {
    vector<mint> a(size_fft), b(size_fft), c(size_fft);
    for (int i = 0; i < N; ++i)
      a[i] = A[i];
    for (int i = 0; i < M; ++i)
      b[i] = B[i];
    trans(a), trans(b);
    vector<mint> res(size_fft);
    for (int i = 0; i < size_fft; ++i)
      res[i] = a[i] * b[i];
    trans(res, true);
    res.resize(N + M - 1);
    return res;
  }
  vector<mint0> a0(size_fft, 0), b0(size_fft, 0), c0(size_fft, 0);
  vector<mint1> a1(size_fft, 0), b1(size_fft, 0), c1(size_fft, 0);
  vector<mint2> a2(size_fft, 0), b2(size_fft, 0), c2(size_fft, 0);
  for (int i = 0; i < N; ++i)
    a0[i] = A[i].val, a1[i] = A[i].val, a2[i] = A[i].val;
  for (int i = 0; i < M; ++i)
    b0[i] = B[i].val, b1[i] = B[i].val, b2[i] = B[i].val;
  trans(a0), trans(a1), trans(a2), trans(b0), trans(b1), trans(b2);
  for (int i = 0; i < size_fft; ++i) {
    c0[i] = a0[i] * b0[i];
    c1[i] = a1[i] * b1[i];
    c2[i] = a2[i] * b2[i];
  }
  trans(c0, true), trans(c1, true), trans(c2, true);
  static const mint mod0 = MOD0, mod01 = mod0 * MOD1;
  vector<mint> res(N + M - 1);
  for (int i = 0; i < N + M - 1; ++i) {
    int y0 = c0[i].val;
    int y1 = (imod0 * (c1[i] - y0)).val;
    int y2 = (imod01 * (c2[i] - y0) - imod1 * y1).val;
    res[i] = mod01 * y2 + mod0 * y1 + y0;
  }
  return res;
}

// long long
vector<long long> mul_ll(const vector<long long> &A,
                         const vector<long long> &B) {
  if (A.empty() || B.empty())
    return {};
  int N = (int)A.size(), M = (int)B.size();
  if (min(N, M) < 30)
    return naive_mul(A, B);
  int size_fft = get_fft_size(N, M);
  vector<mint0> a0(size_fft, 0), b0(size_fft, 0), c0(size_fft, 0);
  vector<mint1> a1(size_fft, 0), b1(size_fft, 0), c1(size_fft, 0);
  vector<mint2> a2(size_fft, 0), b2(size_fft, 0), c2(size_fft, 0);
  for (int i = 0; i < N; ++i)
    a0[i] = A[i], a1[i] = A[i], a2[i] = A[i];
  for (int i = 0; i < M; ++i)
    b0[i] = B[i], b1[i] = B[i], b2[i] = B[i];
  trans(a0), trans(a1), trans(a2), trans(b0), trans(b1), trans(b2);
  for (int i = 0; i < size_fft; ++i) {
    c0[i] = a0[i] * b0[i];
    c1[i] = a1[i] * b1[i];
    c2[i] = a2[i] * b2[i];
  }
  trans(c0, true), trans(c1, true), trans(c2, true);
  static const long long mod0 = MOD0, mod01 = mod0 * MOD1;
  vector<long long> res(N + M - 1);
  for (int i = 0; i < N + M - 1; ++i) {
    int y0 = c0[i].val;
    int y1 = (imod0 * (c1[i] - y0)).val;
    int y2 = (imod01 * (c2[i] - y0) - imod1 * y1).val;
    res[i] = mod01 * y2 + mod0 * y1 + y0;
  }
  return res;
}
}; // namespace NTT

// Binomial coefficient
template <class T> struct BiCoef {
  vector<T> fact_, inv_, finv_;
  constexpr BiCoef() {}
  constexpr BiCoef(int n) noexcept : fact_(n, 1), inv_(n, 1), finv_(n, 1) {
    init(n);
  }
  constexpr void init(int n) noexcept {
    fact_.assign(n, 1), inv_.assign(n, 1), finv_.assign(n, 1);
    int MOD = fact_[0].getmod();
    for (int i = 2; i < n; i++) {
      fact_[i] = fact_[i - 1] * i;
      inv_[i] = -inv_[MOD % i] * (MOD / i);
      finv_[i] = finv_[i - 1] * inv_[i];
    }
  }
  constexpr T com(int n, int k) const noexcept {
    if (n < k || n < 0 || k < 0)
      return 0;
    return fact_[n] * finv_[k] * finv_[n - k];
  }
  constexpr T fact(int n) const noexcept {
    if (n < 0)
      return 0;
    return fact_[n];
  }
  constexpr T inv(int n) const noexcept {
    if (n < 0)
      return 0;
    return inv_[n];
  }
  constexpr T finv(int n) const noexcept {
    if (n < 0)
      return 0;
    return finv_[n];
  }
};

// Formal Power Series
template <typename mint> struct FPS : vector<mint> {
  using vector<mint>::vector;

  // constructor
  FPS(mint v = 0) : vector<mint>(1, v) {}
  FPS(int siz, mint v) : vector<mint>(siz, v) {}
  FPS(const vector<mint> &r) : vector<mint>(r) {}

  // core operator
  FPS pre(int siz) const noexcept {
    return FPS(begin(*this), begin(*this) + min((int)this->size(), siz));
  }
  FPS rev() const noexcept {
    reverse(begin(*this), end(*this));
    return *this;
  }
  FPS &normalize() noexcept {
    while (!this->empty() && this->back() == 0)
      this->pop_back();
    return *this;
  }
  FPS inv(int deg) const noexcept {
    assert((*this)[0] != 0);
    if (deg < 0)
      deg = (int)this->size();
    FPS res({mint(1) / (*this)[0]});
    for (int i = 1; i < deg; i <<= 1) {
      res = (res + res - res * res * this->pre(i << 1)).pre(i << 1);
    }
    return res.pre(deg);
  }

  // each operator
  FPS operator-() const noexcept {
    for (int i = 0; i < (int)this->size(); ++i)
      (*this)[i] = -(*this)[i];
    return *this;
  }
  FPS operator+(const FPS &r) const noexcept { return FPS(*this) += r; }
  FPS operator-(const FPS &r) const noexcept { return FPS(*this) -= r; }
  FPS operator*(mint v) const noexcept { return FPS(*this) *= v; }
  FPS operator*(const FPS &r) const noexcept { return FPS(*this) *= r; }
  FPS operator/(mint v) const noexcept { return FPS(*this) /= v; }
  FPS operator/(const FPS &r) const noexcept { return FPS(*this) /= r; }
  FPS operator%(mint v) const noexcept { return FPS(*this) %= v; }
  FPS operator%(const FPS &r) const noexcept { return FPS(*this) %= r; }
  FPS &operator+=(const FPS &r) {
    if (r.size() > this->size())
      this->resize(r.size());
    for (int i = 0; i < (int)r.size(); ++i)
      (*this)[i] += r[i];
    return this->normalize();
  }
  FPS &operator-=(const FPS &r) {
    if (r.size() > this->size())
      this->resize(r.size());
    for (int i = 0; i < (int)r.size(); ++i)
      (*this)[i] -= r[i];
    return this->normalize();
  }
  FPS &operator*=(const mint &v) {
    for (int i = 0; i < (int)this->size(); ++i)
      (*this)[i] *= v;
    return *this;
  }
  FPS &operator*=(const FPS &r) { return *this = NTT::mul((*this), r); }
  FPS &operator/=(const mint &v) {
    assert(v != 0);
    mint iv = v.inv();
    for (int i = 0; i < (int)this->size(); ++i)
      (*this)[i] *= iv;
    return *this;
  }
  FPS &operator/=(const FPS &r) {
    if (this->size() < r.size()) {
      this->clear();
      return *this;
    }
    int need = (int)this->size() - (int)r.size() + 1;
    *this = ((*this).rev().pre(need) * r.rev().inv(need)).pre(need).rev();
    return *this;
  }
};

const int MOD = 998244353;
using mint = Fp<MOD>;

int main() {
  int N, K;
  cin >> N >> K;
  FPS<mint> f(N + 1, 0), one = mint(1);
  for (int i = 0; i < K; ++i) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; ++j)
      f[j] = 1;
  }
  auto g = one - f;
  auto res = g.inv(N + 10);

  //  COUT(g); COUT(res);

  if (res.size() < N)
    cout << res[N - 1] << endl;
  else
    cout << 0 << endl;
}

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

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template <class T1, class T2> ostream &operator<<(ostream &s, pair<T1, T2> P) {
  return s << '<' << P.first << ", " << P.second << '>';
}
template <class T> ostream &operator<<(ostream &s, vector<T> P) {
  for (int i = 0; i < P.size(); ++i) {
    if (i > 0) {
      s << " ";
    }
    s << P[i];
  }
  return s;
}
template <class T> ostream &operator<<(ostream &s, vector<vector<T>> P) {
  for (int i = 0; i < P.size(); ++i) {
    s << endl << P[i];
  }
  return s << endl;
}
template <class T> ostream &operator<<(ostream &s, set<T> P) {
  for (auto it : P) {
    s << "<" << it << "> ";
  }
  return s << endl;
}
template <class T1, class T2> ostream &operator<<(ostream &s, map<T1, T2> P) {
  for (auto it : P) {
    s << "<" << it.first << "->" << it.second << "> ";
  }
  return s << endl;
}

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

namespace NTT {
long long modpow(long long a, long long n, int mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

long long modinv(long long a, int mod) {
  long long b = mod, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b, swap(a, b);
    u -= t * v, swap(u, v);
  }
  u %= mod;
  if (u < 0)
    u += mod;
  return u;
}

int calc_primitive_root(int mod) {
  if (mod == 2)
    return 1;
  if (mod == 167772161)
    return 3;
  if (mod == 469762049)
    return 3;
  if (mod == 754974721)
    return 11;
  if (mod == 998244353)
    return 3;
  int divs[20] = {};
  divs[0] = 2;
  int cnt = 1;
  long long x = (mod - 1) / 2;
  while (x % 2 == 0)
    x /= 2;
  for (long long i = 3; i * i <= x; i += 2) {
    if (x % i == 0) {
      divs[cnt++] = i;
      while (x % i == 0)
        x /= i;
    }
  }
  if (x > 1)
    divs[cnt++] = x;
  for (int g = 2;; g++) {
    bool ok = true;
    for (int i = 0; i < cnt; i++) {
      if (modpow(g, (mod - 1) / divs[i], mod) == 1) {
        ok = false;
        break;
      }
    }
    if (ok)
      return g;
  }
}

int get_fft_size(int N, int M) {
  int size_a = 1, size_b = 1;
  while (size_a < N)
    size_a <<= 1;
  while (size_b < M)
    size_b <<= 1;
  return max(size_a, size_b) << 1;
}

// number-theoretic transform
template <class mint> void trans(vector<mint> &v, bool inv = false) {
  if (v.empty())
    return;
  int N = (int)v.size();
  int MOD = v[0].getmod();
  int PR = calc_primitive_root(MOD);
  static bool first = true;
  static vector<long long> vbw(30), vibw(30);
  if (first) {
    first = false;
    for (int k = 0; k < 30; ++k) {
      vbw[k] = modpow(PR, (MOD - 1) >> (k + 1), MOD);
      vibw[k] = modinv(vbw[k], MOD);
    }
  }
  for (int i = 0, j = 1; j < N - 1; j++) {
    for (int k = N >> 1; k > (i ^= k); k >>= 1)
      ;
    if (i > j)
      swap(v[i], v[j]);
  }
  for (int k = 0, t = 2; t <= N; ++k, t <<= 1) {
    long long bw = vbw[k];
    if (inv)
      bw = vibw[k];
    for (int i = 0; i < N; i += t) {
      mint w = 1;
      for (int j = 0; j < t / 2; ++j) {
        int j1 = i + j, j2 = i + j + t / 2;
        mint c1 = v[j1], c2 = v[j2] * w;
        v[j1] = c1 + c2;
        v[j2] = c1 - c2;
        w *= bw;
      }
    }
  }
  if (inv) {
    long long invN = modinv(N, MOD);
    for (int i = 0; i < N; ++i)
      v[i] = v[i] * invN;
  }
}

// for garner
static constexpr int MOD0 = 754974721;
static constexpr int MOD1 = 167772161;
static constexpr int MOD2 = 469762049;
using mint0 = Fp<MOD0>;
using mint1 = Fp<MOD1>;
using mint2 = Fp<MOD2>;
static const mint1 imod0 = 95869806;   // modinv(MOD0, MOD1);
static const mint2 imod1 = 104391568;  // modinv(MOD1, MOD2);
static const mint2 imod01 = 187290749; // imod1 / MOD0;

// small case (T = mint, long long)
template <class T> vector<T> naive_mul(const vector<T> &A, const vector<T> &B) {
  if (A.empty() || B.empty())
    return {};
  int N = (int)A.size(), M = (int)B.size();
  vector<T> res(N + M - 1);
  for (int i = 0; i < N; ++i)
    for (int j = 0; j < M; ++j)
      res[i + j] += A[i] * B[j];
  return res;
}

// mint
template <class mint>
vector<mint> mul(const vector<mint> &A, const vector<mint> &B) {
  if (A.empty() || B.empty())
    return {};
  int N = (int)A.size(), M = (int)B.size();
  if (min(N, M) < 30)
    return naive_mul(A, B);
  int MOD = A[0].getmod();
  int size_fft = get_fft_size(N, M);
  if (MOD == 998244353) {
    vector<mint> a(size_fft), b(size_fft), c(size_fft);
    for (int i = 0; i < N; ++i)
      a[i] = A[i];
    for (int i = 0; i < M; ++i)
      b[i] = B[i];
    trans(a), trans(b);
    vector<mint> res(size_fft);
    for (int i = 0; i < size_fft; ++i)
      res[i] = a[i] * b[i];
    trans(res, true);
    res.resize(N + M - 1);
    return res;
  }
  vector<mint0> a0(size_fft, 0), b0(size_fft, 0), c0(size_fft, 0);
  vector<mint1> a1(size_fft, 0), b1(size_fft, 0), c1(size_fft, 0);
  vector<mint2> a2(size_fft, 0), b2(size_fft, 0), c2(size_fft, 0);
  for (int i = 0; i < N; ++i)
    a0[i] = A[i].val, a1[i] = A[i].val, a2[i] = A[i].val;
  for (int i = 0; i < M; ++i)
    b0[i] = B[i].val, b1[i] = B[i].val, b2[i] = B[i].val;
  trans(a0), trans(a1), trans(a2), trans(b0), trans(b1), trans(b2);
  for (int i = 0; i < size_fft; ++i) {
    c0[i] = a0[i] * b0[i];
    c1[i] = a1[i] * b1[i];
    c2[i] = a2[i] * b2[i];
  }
  trans(c0, true), trans(c1, true), trans(c2, true);
  static const mint mod0 = MOD0, mod01 = mod0 * MOD1;
  vector<mint> res(N + M - 1);
  for (int i = 0; i < N + M - 1; ++i) {
    int y0 = c0[i].val;
    int y1 = (imod0 * (c1[i] - y0)).val;
    int y2 = (imod01 * (c2[i] - y0) - imod1 * y1).val;
    res[i] = mod01 * y2 + mod0 * y1 + y0;
  }
  return res;
}

// long long
vector<long long> mul_ll(const vector<long long> &A,
                         const vector<long long> &B) {
  if (A.empty() || B.empty())
    return {};
  int N = (int)A.size(), M = (int)B.size();
  if (min(N, M) < 30)
    return naive_mul(A, B);
  int size_fft = get_fft_size(N, M);
  vector<mint0> a0(size_fft, 0), b0(size_fft, 0), c0(size_fft, 0);
  vector<mint1> a1(size_fft, 0), b1(size_fft, 0), c1(size_fft, 0);
  vector<mint2> a2(size_fft, 0), b2(size_fft, 0), c2(size_fft, 0);
  for (int i = 0; i < N; ++i)
    a0[i] = A[i], a1[i] = A[i], a2[i] = A[i];
  for (int i = 0; i < M; ++i)
    b0[i] = B[i], b1[i] = B[i], b2[i] = B[i];
  trans(a0), trans(a1), trans(a2), trans(b0), trans(b1), trans(b2);
  for (int i = 0; i < size_fft; ++i) {
    c0[i] = a0[i] * b0[i];
    c1[i] = a1[i] * b1[i];
    c2[i] = a2[i] * b2[i];
  }
  trans(c0, true), trans(c1, true), trans(c2, true);
  static const long long mod0 = MOD0, mod01 = mod0 * MOD1;
  vector<long long> res(N + M - 1);
  for (int i = 0; i < N + M - 1; ++i) {
    int y0 = c0[i].val;
    int y1 = (imod0 * (c1[i] - y0)).val;
    int y2 = (imod01 * (c2[i] - y0) - imod1 * y1).val;
    res[i] = mod01 * y2 + mod0 * y1 + y0;
  }
  return res;
}
}; // namespace NTT

// Binomial coefficient
template <class T> struct BiCoef {
  vector<T> fact_, inv_, finv_;
  constexpr BiCoef() {}
  constexpr BiCoef(int n) noexcept : fact_(n, 1), inv_(n, 1), finv_(n, 1) {
    init(n);
  }
  constexpr void init(int n) noexcept {
    fact_.assign(n, 1), inv_.assign(n, 1), finv_.assign(n, 1);
    int MOD = fact_[0].getmod();
    for (int i = 2; i < n; i++) {
      fact_[i] = fact_[i - 1] * i;
      inv_[i] = -inv_[MOD % i] * (MOD / i);
      finv_[i] = finv_[i - 1] * inv_[i];
    }
  }
  constexpr T com(int n, int k) const noexcept {
    if (n < k || n < 0 || k < 0)
      return 0;
    return fact_[n] * finv_[k] * finv_[n - k];
  }
  constexpr T fact(int n) const noexcept {
    if (n < 0)
      return 0;
    return fact_[n];
  }
  constexpr T inv(int n) const noexcept {
    if (n < 0)
      return 0;
    return inv_[n];
  }
  constexpr T finv(int n) const noexcept {
    if (n < 0)
      return 0;
    return finv_[n];
  }
};

// Formal Power Series
template <typename mint> struct FPS : vector<mint> {
  using vector<mint>::vector;

  // constructor
  FPS(long long v) : vector<mint>(1, mint(v)) {}
  FPS(mint v) : vector<mint>(1, v) {}
  FPS(int siz, mint v) : vector<mint>(siz, v) {}
  FPS(const vector<mint> &r) : vector<mint>(r) {}

  // core operator
  FPS pre(int siz) const noexcept {
    return FPS(begin(*this), begin(*this) + min((int)this->size(), siz));
  }
  FPS rev() const noexcept {
    reverse(begin(*this), end(*this));
    return *this;
  }
  FPS &normalize() noexcept {
    while (!this->empty() && this->back() == 0)
      this->pop_back();
    return *this;
  }
  FPS inv(int deg) const noexcept {
    assert((*this)[0] != 0);
    if (deg < 0)
      deg = (int)this->size();
    FPS res({mint(1) / (*this)[0]});
    for (int i = 1; i < deg; i <<= 1) {
      res = (res + res - res * res * this->pre(i << 1)).pre(i << 1);
    }
    return res.pre(deg);
  }

  // each operator
  FPS operator-() const noexcept {
    for (int i = 0; i < (int)this->size(); ++i)
      (*this)[i] = -(*this)[i];
    return *this;
  }
  FPS operator+(const FPS &r) const noexcept { return FPS(*this) += r; }
  FPS operator-(const FPS &r) const noexcept { return FPS(*this) -= r; }
  FPS operator*(mint v) const noexcept { return FPS(*this) *= v; }
  FPS operator*(const FPS &r) const noexcept { return FPS(*this) *= r; }
  FPS operator/(mint v) const noexcept { return FPS(*this) /= v; }
  FPS operator/(const FPS &r) const noexcept { return FPS(*this) /= r; }
  FPS operator%(mint v) const noexcept { return FPS(*this) %= v; }
  FPS operator%(const FPS &r) const noexcept { return FPS(*this) %= r; }
  FPS &operator+=(const FPS &r) {
    if (r.size() > this->size())
      this->resize(r.size());
    for (int i = 0; i < (int)r.size(); ++i)
      (*this)[i] += r[i];
    return this->normalize();
  }
  FPS &operator-=(const FPS &r) {
    if (r.size() > this->size())
      this->resize(r.size());
    for (int i = 0; i < (int)r.size(); ++i)
      (*this)[i] -= r[i];
    return this->normalize();
  }
  FPS &operator*=(const mint &v) {
    for (int i = 0; i < (int)this->size(); ++i)
      (*this)[i] *= v;
    return *this;
  }
  FPS &operator*=(const FPS &r) { return *this = NTT::mul((*this), r); }
  FPS &operator/=(const mint &v) {
    assert(v != 0);
    mint iv = v.inv();
    for (int i = 0; i < (int)this->size(); ++i)
      (*this)[i] *= iv;
    return *this;
  }
  FPS &operator/=(const FPS &r) {
    if (this->size() < r.size()) {
      this->clear();
      return *this;
    }
    int need = (int)this->size() - (int)r.size() + 1;
    *this = ((*this).rev().pre(need) * r.rev().inv(need)).pre(need).rev();
    return *this;
  }
};

const int MOD = 998244353;
using mint = Fp<MOD>;

int main() {
  int N, K;
  cin >> N >> K;
  FPS<mint> f(N, 0), one = 1;
  for (int i = 0; i < K; ++i) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; ++j)
      if (j < N)
        f[j] = 1;
  }
  auto g = one - f;
  auto res = g.inv(N + 10);

  // COUT(g); COUT(res);

  if (res.size() >= N)
    cout << res[N - 1] << endl;
  else
    cout << 0 << endl;
}


#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define per(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define sz(v) (int)(v).size()

using namespace std;

typedef long long ll;
typedef long double ld;

using P = pair<int, int>;
template <typename T> struct Edge {
  int u, v;
  T cost;
  Edge(int u, int v, T c) : u(u), v(v), cost(c) {}
  bool operator<(const Edge &e) const { return cost < e.cost; }
};

static const long long mod = 998244353;
static const long long LINF = (ll)(1e18 + 99);
static const int INF = 1e9 + 99;

template <int mod> struct ModInt {
  int x;
  ModInt() : x(0) {}
  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
  ModInt &operator+=(const ModInt &p) {
    if ((x += p.x) >= mod)
      x -= mod;
    return *this;
  }
  ModInt &operator-=(const ModInt &p) {
    if ((x += mod - p.x) >= mod)
      x -= mod;
    return *this;
  }
  ModInt &operator*=(const ModInt &p) {
    x = (int)(1LL * x * p.x % mod);
    return *this;
  }
  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }
  ModInt operator-() const { return ModInt(-x); }
  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
  bool operator==(const ModInt &p) const { return x == p.x; }
  bool operator!=(const ModInt &p) const { return x != p.x; }
  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while (b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }
  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while (n > 0) {
      if (n & 1)
        ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }
  friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; }
  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt<mod>(t);
    return (is);
  }
  static int get_mod() { return mod; }
};
using mint = ModInt<mod>;

ll ans;
mint dp[200005];

int main(void) {
  int n, k;
  cin >> n >> k;
  vector<int> v;
  rep(i, 0, k) {
    int L, R;
    cin >> L >> R;
    rep(j, L, R + 1) v.pb(j);
  }
  sort(all(v));

  dp[1] = 1;
  rep(i, 2, n + 1) {
    rep(j, 0, sz(v)) {
      if (i - v[j] >= 0)
        dp[i] += dp[i - v[j]];
    }
  }

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

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define per(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define sz(v) (int)(v).size()

using namespace std;

typedef long long ll;
typedef long double ld;

using P = pair<int, int>;
template <typename T> struct Edge {
  int u, v;
  T cost;
  Edge(int u, int v, T c) : u(u), v(v), cost(c) {}
  bool operator<(const Edge &e) const { return cost < e.cost; }
};

static const long long mod = 998244353;
static const long long LINF = (ll)(1e18 + 99);
static const int INF = 1e9 + 99;

template <int mod> struct ModInt {
  int x;
  ModInt() : x(0) {}
  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
  ModInt &operator+=(const ModInt &p) {
    if ((x += p.x) >= mod)
      x -= mod;
    return *this;
  }
  ModInt &operator-=(const ModInt &p) {
    if ((x += mod - p.x) >= mod)
      x -= mod;
    return *this;
  }
  ModInt &operator*=(const ModInt &p) {
    x = (int)(1LL * x * p.x % mod);
    return *this;
  }
  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }
  ModInt operator-() const { return ModInt(-x); }
  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
  bool operator==(const ModInt &p) const { return x == p.x; }
  bool operator!=(const ModInt &p) const { return x != p.x; }
  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while (b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }
  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while (n > 0) {
      if (n & 1)
        ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }
  friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; }
  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt<mod>(t);
    return (is);
  }
  static int get_mod() { return mod; }
};
using mint = ModInt<mod>;

ll ans;
mint dp[200005];
mint S[200005];
vector<int> L, R;

int main(void) {
  int n, k;
  cin >> n >> k;
  vector<int> v;
  rep(i, 0, k) {
    int l, r;
    cin >> l >> r;
    L.pb(l);
    R.pb(r);
  }

  dp[1] = 1;
  S[1] = 1;
  rep(i, 2, n + 1) {
    rep(j, 0, k) {
      int l = i - R[j], r = i - L[j];
      if (r < 1)
        continue;
      mint x = S[r] - S[max(0, l - 1)];
      dp[i] += x;
    }
    S[i] += S[i - 1] + dp[i];
  }

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


#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
#define all(x) x.begin(), x.end()
#define trav(i, a) for (auto &i : a)
inline int in() {
  int x;
  scanf("%lld", &x);
  return x;
}
const int mod = 998244353;
const int N = 4e5 + 8;
int pre[N], a[N];
int l[11], r[11];
int32_t main() {
  int n = in();
  int k = in();
  for (int i = 1; i <= k; i++)
    l[i] = in(), r[i] = in();
  a[1] = 1;
  for (int i = 1; i <= n; i++) {
    if (a[i] == 0 and i != 1)
      continue;
    for (int j = 1; j <= k; j++) {
      pre[i + l[j]] += a[i];
      pre[i + r[j] + 1] -= a[i];
    }
    for (int i = 1; i <= n; i++) {
      pre[i] += pre[i - 1];
      pre[i] %= mod;
    }

    for (int i = 1; i <= n; i++) {
      a[i] += pre[i];
      a[i] %= mod;
      pre[i] = 0;
    }
    // for(int i=1;i<=n;i++)cout<<a[i]<<" ";
    // cout<<"\\n";
  }
  cout << a[n] % mod;
}

#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
#define all(x) x.begin(), x.end()
#define trav(i, a) for (auto &i : a)
inline int in() {
  int x;
  scanf("%lld", &x);
  return x;
}
const int mod = 998244353;
const int N = 3e5 + 4;
int tree[N], n, k, r[11], l[11];
void add(int x, int val) {
  while (x <= n) {
    tree[x] += val;
    tree[x] %= mod;
    tree[x] += mod;
    tree[x] %= mod;
    x += (x & -x);
  }
}
int sum(int x) {
  int ans = 0;
  while (x >= 1) {
    ans += tree[x];
    ans %= mod;
    ans += mod;
    ans %= mod;
    x -= (x & -x);
  }
  return ans;
}

int32_t main() {
  n = in();
  k = in();
  for (int i = 1; i <= k; i++)
    l[i] = in(), r[i] = in();
  add(1, 1);
  add(2, -1);
  for (int i = 1; i <= n; i++) {
    int val = sum(i);
    if (1) {
      for (int j = 1; j <= k; j++) {
        add(i + l[j], val);
        add(i + r[j] + 1, -val);
      }
    }
  }
  cout << sum(n) % mod;
}


//---------------------------------------------------------------
#include <bits/stdc++.h>
using namespace std;
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <math.h>
#include <numeric>
#include <sstream>
#include <vector>
//---------------------------------------------------------------
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define SIZE 100005
#define INF 1e18
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define vec vector
using pint = pair<int, int>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
//---------------------------------------------------------------
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const double pi = acos(-1);
//---------------------------------------------------------------

// ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

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

  ll mod = 998244353;

  ll n, k;
  cin >> n >> k;

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

  vll dp(n, 0);
  dp[0] = 1;
  rep(i, n - 1) {
    rep(j, k) {
      for (ll key = l[j]; key <= r[j]; key++) {
        if (i + key < n && dp[i] != 0) {
          dp[i + key] += dp[i];
        }
      }
    }
  }

  cout << dp[n - 1] % mod << endl;
}

//---------------------------------------------------------------
#include <bits/stdc++.h>
using namespace std;
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <math.h>
#include <numeric>
#include <sstream>
#include <vector>
//---------------------------------------------------------------
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define SIZE 100005
#define INF 1e18
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define vec vector
using pint = pair<int, int>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
//---------------------------------------------------------------
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const double pi = acos(-1);
//---------------------------------------------------------------
ll mod = 998244353;
struct mint {
  int64_t x;
  mint(int64_t x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a) {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a) {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(int64_t t) const {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }
  mint inv() const { return pow(mod - 2); }
  mint &operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) { 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() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  ll mod = 998244353;

  ll n, k;
  cin >> n >> k;

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

  vec<mint> dp(1000000, 0);
  dp[0] = 1;
  dp[1] = -1;
  rep(i, n) {
    if (i > 0)
      dp[i] += dp[i - 1];
    rep(j, k) {
      if (i + l[j] < n) {
        dp[i + l[j]] += dp[i];
      }
      if (i + r[j] + 1 < n) {
        dp[i + r[j] + 1] -= dp[i];
      }
    }
  }

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


#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
using ll = long long int;
const ll MOD = 998244353;

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

  vector<int> isexist_s(n + 5, 0);
  for (int i = 0; i < k; i++) {
    isexist_s[l[i]]++;
    isexist_s[r[i] + 1]--;
  }
  for (int i = 1; i < n + 5; i++)
    isexist_s[i] += isexist_s[i - 1];

  vector<int> move;
  for (int i = 1; i <= n; i++) {
    if (isexist_s[i])
      move.push_back(i);
  }

  vector<ll> memo(n + 1, 0);
  memo[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < move.size() && i - move[j] >= 0; j++) {
      memo[i] += memo[i - move[j]];
      memo[i] %= MOD;
    }
  }

  cout << memo[n] << endl;
  return 0;
}

#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
using ll = long long int;
const ll MOD = 998244353;

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

  vector<int> isexist_s(n + 5, 0);
  for (int i = 0; i < k; i++) {
    isexist_s[l[i]]++;
    isexist_s[r[i] + 1]--;
  }
  for (int i = 1; i < n + 5; i++)
    isexist_s[i] += isexist_s[i - 1];

  vector<int> move;
  for (int i = 1; i <= n; i++) {
    if (isexist_s[i])
      move.push_back(i);
  }

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

      memo[i] += submemo[j];
      memo[i] %= MOD;
    }
  }

  cout << memo[n] << endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
#define REP(i, n) for (int i = 0; i < n; i++)
#define REP1(i, n) for (int i = 1; i <= n; i++)
#define RST(i, n) memset(i, n, sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define X first
#define Y second
#define eb emplace_back
#ifdef cold66
#define debug(...)                                                             \\
  do {                                                                         \\
    fprintf(stderr, "LINE %d: (%s) = ", __LINE__, #__VA_ARGS__);               \\
    _do(__VA_ARGS__);                                                          \\
  } while (0)
template <typename T> void _do(T &&_x) { cerr << _x << endl; }
template <typename T, typename... S> void _do(T &&_x, S &&..._t) {
  cerr << _x << ", ";
  _do(_t...);
}
template <typename _a, typename _b>
ostream &operator<<(ostream &_s, const pair<_a, _b> &_p) {
  return _s << "(" << _p.X << "," << _p.Y << ")";
}
template <typename It> ostream &_OUTC(ostream &_s, It _ita, It _itb) {
  _s << "{";
  for (It _it = _ita; _it != _itb; _it++) {
    _s << (_it == _ita ? "" : ",") << *_it;
  }
  _s << "}";
  return _s;
}
template <typename _a> ostream &operator<<(ostream &_s, vector<_a> &_c) {
  return _OUTC(_s, ALL(_c));
}
template <typename _a> ostream &operator<<(ostream &_s, set<_a> &_c) {
  return _OUTC(_s, ALL(_c));
}
template <typename _a, typename _b>
ostream &operator<<(ostream &_s, map<_a, _b> &_c) {
  return _OUTC(_s, ALL(_c));
}
template <typename _t> void pary(_t _a, _t _b) {
  _OUTC(cerr, _a, _b);
  cerr << endl;
}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\\n'
#define IOS()                                                                  \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);
#endif // cold66
//}
template <class T> inline bool chkmax(T &a, const T &b) {
  return b > a ? a = b, true : false;
}
template <class T> inline bool chkmin(T &a, const T &b) {
  return b < a ? a = b, true : false;
}

const ll MAXn = 1e5 + 5, MAXlg = __lg(MAXn) + 2;
const ll MOD = 998244353;
const ll INF = 0x3f3f3f3f;

ll dp[MAXn], sum[MAXn];
ii d[MAXn];
ll add(ll x, ll y) {
  ll ret = x + y;
  if (ret >= MOD)
    ret -= MOD;
  return ret;
}
ll sub(ll a, ll b) {
  ll ret = a - b;
  if (ret < 0)
    ret += MOD;
  return ret;
}
int main() {
  IOS();
  ll n, k;
  cin >> n >> k;
  for (int i = 0; i < k; ++i) {
    cin >> d[i].X >> d[i].Y;
  }
  sort(d, d + k);

  dp[1] = 1;
  sum[1] = 1;
  for (int i = 2; i <= n; ++i)
    sum[i] = 1;
  for (ll i = 2; i <= n; ++i) {
    for (ll j = 0; j < k; ++j) {
      debug(i);
      ll r = i - d[j].X, l = max(0LL, i - d[j].Y - 1);
      if (r < 0)
        break;
      debug(l, r);
      dp[i] = add(dp[i], sub(sum[r], sum[l]));
    }
    sum[i] = add(sum[i - 1], dp[i]);
  }
  cout << dp[n] << endl;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
#define REP(i, n) for (int i = 0; i < n; i++)
#define REP1(i, n) for (int i = 1; i <= n; i++)
#define RST(i, n) memset(i, n, sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define X first
#define Y second
#define eb emplace_back
#ifdef cold66
#define debug(...)                                                             \\
  do {                                                                         \\
    fprintf(stderr, "LINE %d: (%s) = ", __LINE__, #__VA_ARGS__);               \\
    _do(__VA_ARGS__);                                                          \\
  } while (0)
template <typename T> void _do(T &&_x) { cerr << _x << endl; }
template <typename T, typename... S> void _do(T &&_x, S &&..._t) {
  cerr << _x << ", ";
  _do(_t...);
}
template <typename _a, typename _b>
ostream &operator<<(ostream &_s, const pair<_a, _b> &_p) {
  return _s << "(" << _p.X << "," << _p.Y << ")";
}
template <typename It> ostream &_OUTC(ostream &_s, It _ita, It _itb) {
  _s << "{";
  for (It _it = _ita; _it != _itb; _it++) {
    _s << (_it == _ita ? "" : ",") << *_it;
  }
  _s << "}";
  return _s;
}
template <typename _a> ostream &operator<<(ostream &_s, vector<_a> &_c) {
  return _OUTC(_s, ALL(_c));
}
template <typename _a> ostream &operator<<(ostream &_s, set<_a> &_c) {
  return _OUTC(_s, ALL(_c));
}
template <typename _a, typename _b>
ostream &operator<<(ostream &_s, map<_a, _b> &_c) {
  return _OUTC(_s, ALL(_c));
}
template <typename _t> void pary(_t _a, _t _b) {
  _OUTC(cerr, _a, _b);
  cerr << endl;
}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\\n'
#define IOS()                                                                  \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);
#endif // cold66
//}
template <class T> inline bool chkmax(T &a, const T &b) {
  return b > a ? a = b, true : false;
}
template <class T> inline bool chkmin(T &a, const T &b) {
  return b < a ? a = b, true : false;
}

const ll MAXn = 2e5 + 5, MAXlg = __lg(MAXn) + 2;
const ll MOD = 998244353;
const ll INF = 0x3f3f3f3f;

ll dp[MAXn], sum[MAXn];
ii d[MAXn];
ll add(ll x, ll y) {
  ll ret = x + y;
  if (ret >= MOD)
    ret -= MOD;
  return ret;
}
ll sub(ll a, ll b) {
  ll ret = a - b;
  if (ret < 0)
    ret += MOD;
  return ret;
}
int main() {
  IOS();
  ll n, k;
  cin >> n >> k;
  for (int i = 0; i < k; ++i) {
    cin >> d[i].X >> d[i].Y;
  }
  sort(d, d + k);

  dp[1] = 1;
  sum[1] = 1;
  for (int i = 2; i <= n; ++i)
    sum[i] = 1;
  for (ll i = 2; i <= n; ++i) {
    for (ll j = 0; j < k; ++j) {
      debug(i);
      ll r = i - d[j].X, l = max(0LL, i - d[j].Y - 1);
      if (r < 0)
        break;
      debug(l, r);
      dp[i] = add(dp[i], sub(sum[r], sum[l]));
    }
    sum[i] = add(sum[i - 1], dp[i]);
  }
  cout << dp[n] << endl;
}


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

// long long
using ll = long long;

// pair<int, int>
using PII = pair<int, int>;

// 最大値、mod
const int MOD = 1000000007;
const int mod = 1000000007;
const int INF = 1000000000;
const long long LINF = 1e18;
const int MAX = 510000;

// 出力系
#define print(x) cout << x << endl
#define prints(x) cout << fixed << setprecision(20) << x << endl
#define printc(x) cout << setw(2) << setfill('0') << x << endl;
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl

// 配列入力
vector<long long> vecin(ll n) {
  vector<long long> res(n);
  for (int i = 0; i < n; i++)
    cin >> res[i];
  return res;
}

// begin() end()
#define all(x) (x).begin(), (x).end()

// for
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define rrep(i, a, b) for (int i = (a); i > (b); i--)
#define rep(i, a, b) for (int i = (a); i < (b); i++)

// 最大公約数
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

// 最小公倍数
unsigned lcm(unsigned a, unsigned b) { return a / gcd(a, b) * b; }

// a = max(a, b), a = min(a, b)
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;
}

// num ^ pow(mod取る)
ll pow_mod(ll num, ll pow, ll mod) {
  ll prod = 1;
  num %= mod;
  while (pow > 0) {
    if (pow & 1)
      prod = prod * num % mod;
    num = num * num % mod;
    pow >>= 1;
  }
  return prod;
}

// 二項係数(MODとる、1 ≦ k ≦ n ≦ 10^7 程度)
// COMinit()
// COM(x, y)
// とコンビで使う

// テーブルを作る前処理
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// 重みつきUnionFInd
template <class Abel> struct GUnionFind {
  vector<int> par;
  vector<int> rank;
  vector<Abel> diff_weight;

  GUnionFind(int n = 1, Abel SUM_UNITY = 0) { init(n, SUM_UNITY); }

  void init(int n = 1, Abel SUM_UNITY = 0) {
    par.resize(n);
    rank.resize(n);
    diff_weight.resize(n);
    for (int i = 0; i < n; ++i)
      par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY;
  }

  int root(int x) {
    if (par[x] == x) {
      return x;
    } else {
      int r = root(par[x]);
      diff_weight[x] += diff_weight[par[x]];
      return par[x] = r;
    }
  }

  Abel weight(int x) {
    root(x);
    return diff_weight[x];
  }

  bool issame(int x, int y) { return root(x) == root(y); }

  bool merge(int x, int y, Abel w) {
    w += weight(x);
    w -= weight(y);
    x = root(x);
    y = root(y);
    if (x == y)
      return false;
    if (rank[x] < rank[y])
      swap(x, y), w = -w;
    if (rank[x] == rank[y])
      ++rank[x];
    par[y] = x;
    diff_weight[y] = w;
    return true;
  }

  Abel diff(int x, int y) { return weight(y) - weight(x); }
};

// UnionFind
struct UnionFind {
  vector<int> par;
  vector<int> rank;
  vector<ll> Size;
  UnionFind(int n = 1) { init(n); }

  void init(int n = 1) {
    par.resize(n + 1);
    rank.resize(n + 1);
    Size.resize(n + 1);
    for (int i = 0; i <= n; ++i)
      par[i] = i, rank[i] = 0, Size[i] = 1;
  }

  int root(int x) {
    if (par[x] == x) {
      return x;
    } else {
      int r = root(par[x]);
      return par[x] = r;
    }
  }

  bool issame(int x, int y) { return root(x) == root(y); }

  bool merge(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y)
      return false;
    if (rank[x] < rank[y])
      swap(x, y);
    if (rank[x] == rank[y])
      ++rank[x];
    par[y] = x;
    Size[x] += Size[y];
    return true;
  }

  ll size(int x) { return Size[root(x)]; }
};

// modint構造体
struct Mint {
  int val;
  Mint inv() const {
    int tmp, a = val, b = mod, x = 1, y = 0;
    while (b)
      tmp = a / b, a -= tmp * b, swap(a, b), x -= tmp * y, swap(x, y);
    return Mint(x);
  }

public:
  Mint() : val(0) {}
  Mint(ll x) {
    if ((val = x % mod) < 0)
      val += mod;
  }
  Mint pow(ll t) {
    Mint res = 1, b = *this;
    while (t) {
      if (t & 1)
        res *= b;
      b *= b;
      t >>= 1;
    }
    return res;
  }
  Mint &operator+=(const Mint &x) {
    if ((val += x.val) >= mod)
      val -= mod;
    return *this;
  }
  Mint &operator-=(const Mint &x) {
    if ((val += mod - x.val) >= mod)
      val -= mod;
    return *this;
  }
  Mint &operator*=(const Mint &x) {
    val = (ll)val * x.val % mod;
    return *this;
  }
  Mint &operator/=(const Mint &x) { return *this *= x.inv(); }
  bool operator==(const Mint &x) const { return val == x.val; }
  bool operator!=(const Mint &x) const { return val != x.val; }
  bool operator<(const Mint &x) const { return val < x.val; }
  bool operator<=(const Mint &x) const { return val <= x.val; }
  bool operator>(const Mint &x) const { return val > x.val; }
  bool operator>=(const Mint &x) const { return val >= x.val; }
  Mint operator+(const Mint &x) const { return Mint(*this) += x; }
  Mint operator-(const Mint &x) const { return Mint(*this) -= x; }
  Mint operator*(const Mint &x) const { return Mint(*this) *= x; }
  Mint operator/(const Mint &x) const { return Mint(*this) /= x; }
};
struct factorial {
  vector<Mint> Fact, Finv;

public:
  // factorial fact(10000010);
  // fact.nCr(a, b)
  // 「fact」の部分は自由に名前変更可能
  factorial(int maxx) {
    Fact.resize(maxx + 1), Finv.resize(maxx + 1);
    Fact[0] = Mint(1);
    rep(i, 0, maxx) Fact[i + 1] = Fact[i] * (i + 1);
    Finv[maxx] = Mint(1) / Fact[maxx];
    rrep(i, maxx, 0) Finv[i - 1] = Finv[i] * i;
  }
  Mint fact(int n, bool inv = 0) {
    if (inv)
      return Finv[n];
    else
      return Fact[n];
  }
  Mint nPr(int n, int r) {
    if (n < 0 || n < r || r < 0)
      return Mint(0);
    else
      return Fact[n] * Finv[n - r];
  }
  Mint nCr(int n, int r) {
    if (n < 0 || n < r || r < 0)
      return Mint(0);
    else
      return Fact[n] * Finv[r] * Finv[n - r];
  }
};

// 他のnCr使えない場合試す
Mint com2(int n, int a) {
  Mint x = 1, y = 1;
  REP(i, a) {
    x *= n - i;
    y *= i + 1;
  }
  return x / y;
}

// 1 * 2 * 3 .... * n (mod)
ll modfact(ll n) {
  if (n <= 1)
    return 1;
  return (n * modfact(n - 1)) % MOD;
}

// kが角度だった場合:cos(k * (PI / 180));
// const double PI = acos(-1);のまま使うと円周率(M_PIもあるよ)
const double PI = acos(-1);

// 多次元 vector 生成   例: auto dp = make_vec<long long>(N+1, 5, 5, 5);
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

// 素因数分解
vector<pair<long long, int>> factorize(long long n) {
  vector<pair<long long, int>> res;
  for (long long i = 2; i * i <= n; ++i) {
    if (n % i)
      continue;
    res.emplace_back(i, 0);
    while (n % i == 0) {
      n /= i;
      res.back().second++;
    }
  }
  if (n != 1)
    res.emplace_back(n, 1);
  return res;
}

// 素数判定
bool primejudge(long long a) {
  if (a <= 1)
    return false;
  for (long long i = 2; i * i <= a; i++) {
    if (a % i == 0)
      return false;
  }
  return true;
}

int dy[4] = {0, 1, 0, -1}, dx[4] = {1, 0, -1, 0};
vector<int> graph[100010];

int main() {
  int n;
  cin >> n;
  int k;
  cin >> k;
  vector<ll> dp(n + 1, 0);
  set<int> s;
  REP(i, k) {
    int a, b;
    cin >> a >> b;
    for (int i = a; i <= b; i++)
      s.insert(i);
  }
  dp[1] = 1;
  for (int i = 1; i < n; i++) {
    for (auto x : s) {
      if ((i + 1) - x >= 0)
        dp[i + 1] += dp[(i + 1) - x], dp[i + 1] %= 998244353;
    }
  }

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

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

// long long
using ll = long long;

// pair<int, int>
using PII = pair<int, int>;

// 最大値、mod
//  const int MOD = 1000000007;
const int MOD = 998244353;
const int mod = 998244353;
const int INF = 1000000000;
const long long LINF = 1e18;
const int MAX = 510000;

// 出力系
#define print(x) cout << x << endl
#define prints(x) cout << fixed << setprecision(20) << x << endl
#define printc(x) cout << setw(2) << setfill('0') << x << endl;
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl

// 配列入力
vector<long long> vecin(ll n) {
  vector<long long> res(n);
  for (int i = 0; i < n; i++)
    cin >> res[i];
  return res;
}

// begin() end()
#define all(x) (x).begin(), (x).end()

// for
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define rrep(i, a, b) for (int i = (a); i > (b); i--)
#define rep(i, a, b) for (int i = (a); i < (b); i++)

// 最大公約数
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

// 最小公倍数
unsigned lcm(unsigned a, unsigned b) { return a / gcd(a, b) * b; }

// a = max(a, b), a = min(a, b)
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;
}

// num ^ pow(mod取る)
ll pow_mod(ll num, ll pow, ll mod) {
  ll prod = 1;
  num %= mod;
  while (pow > 0) {
    if (pow & 1)
      prod = prod * num % mod;
    num = num * num % mod;
    pow >>= 1;
  }
  return prod;
}

// 二項係数(MODとる、1 ≦ k ≦ n ≦ 10^7 程度)
// COMinit()
// COM(x, y)
// とコンビで使う

// テーブルを作る前処理
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// 重みつきUnionFInd
template <class Abel> struct GUnionFind {
  vector<int> par;
  vector<int> rank;
  vector<Abel> diff_weight;

  GUnionFind(int n = 1, Abel SUM_UNITY = 0) { init(n, SUM_UNITY); }

  void init(int n = 1, Abel SUM_UNITY = 0) {
    par.resize(n);
    rank.resize(n);
    diff_weight.resize(n);
    for (int i = 0; i < n; ++i)
      par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY;
  }

  int root(int x) {
    if (par[x] == x) {
      return x;
    } else {
      int r = root(par[x]);
      diff_weight[x] += diff_weight[par[x]];
      return par[x] = r;
    }
  }

  Abel weight(int x) {
    root(x);
    return diff_weight[x];
  }

  bool issame(int x, int y) { return root(x) == root(y); }

  bool merge(int x, int y, Abel w) {
    w += weight(x);
    w -= weight(y);
    x = root(x);
    y = root(y);
    if (x == y)
      return false;
    if (rank[x] < rank[y])
      swap(x, y), w = -w;
    if (rank[x] == rank[y])
      ++rank[x];
    par[y] = x;
    diff_weight[y] = w;
    return true;
  }

  Abel diff(int x, int y) { return weight(y) - weight(x); }
};

// UnionFind
struct UnionFind {
  vector<int> par;
  vector<int> rank;
  vector<ll> Size;
  UnionFind(int n = 1) { init(n); }

  void init(int n = 1) {
    par.resize(n + 1);
    rank.resize(n + 1);
    Size.resize(n + 1);
    for (int i = 0; i <= n; ++i)
      par[i] = i, rank[i] = 0, Size[i] = 1;
  }

  int root(int x) {
    if (par[x] == x) {
      return x;
    } else {
      int r = root(par[x]);
      return par[x] = r;
    }
  }

  bool issame(int x, int y) { return root(x) == root(y); }

  bool merge(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y)
      return false;
    if (rank[x] < rank[y])
      swap(x, y);
    if (rank[x] == rank[y])
      ++rank[x];
    par[y] = x;
    Size[x] += Size[y];
    return true;
  }

  ll size(int x) { return Size[root(x)]; }
};

// modint構造体
struct Mint {
  int val;
  Mint inv() const {
    int tmp, a = val, b = mod, x = 1, y = 0;
    while (b)
      tmp = a / b, a -= tmp * b, swap(a, b), x -= tmp * y, swap(x, y);
    return Mint(x);
  }

public:
  Mint() : val(0) {}
  Mint(ll x) {
    if ((val = x % mod) < 0)
      val += mod;
  }
  Mint pow(ll t) {
    Mint res = 1, b = *this;
    while (t) {
      if (t & 1)
        res *= b;
      b *= b;
      t >>= 1;
    }
    return res;
  }
  Mint &operator+=(const Mint &x) {
    if ((val += x.val) >= mod)
      val -= mod;
    return *this;
  }
  Mint &operator-=(const Mint &x) {
    if ((val += mod - x.val) >= mod)
      val -= mod;
    return *this;
  }
  Mint &operator*=(const Mint &x) {
    val = (ll)val * x.val % mod;
    return *this;
  }
  Mint &operator/=(const Mint &x) { return *this *= x.inv(); }
  bool operator==(const Mint &x) const { return val == x.val; }
  bool operator!=(const Mint &x) const { return val != x.val; }
  bool operator<(const Mint &x) const { return val < x.val; }
  bool operator<=(const Mint &x) const { return val <= x.val; }
  bool operator>(const Mint &x) const { return val > x.val; }
  bool operator>=(const Mint &x) const { return val >= x.val; }
  Mint operator+(const Mint &x) const { return Mint(*this) += x; }
  Mint operator-(const Mint &x) const { return Mint(*this) -= x; }
  Mint operator*(const Mint &x) const { return Mint(*this) *= x; }
  Mint operator/(const Mint &x) const { return Mint(*this) /= x; }
};
struct factorial {
  vector<Mint> Fact, Finv;

public:
  // factorial fact(10000010);
  // fact.nCr(a, b)
  // 「fact」の部分は自由に名前変更可能
  factorial(int maxx) {
    Fact.resize(maxx + 1), Finv.resize(maxx + 1);
    Fact[0] = Mint(1);
    rep(i, 0, maxx) Fact[i + 1] = Fact[i] * (i + 1);
    Finv[maxx] = Mint(1) / Fact[maxx];
    rrep(i, maxx, 0) Finv[i - 1] = Finv[i] * i;
  }
  Mint fact(int n, bool inv = 0) {
    if (inv)
      return Finv[n];
    else
      return Fact[n];
  }
  Mint nPr(int n, int r) {
    if (n < 0 || n < r || r < 0)
      return Mint(0);
    else
      return Fact[n] * Finv[n - r];
  }
  Mint nCr(int n, int r) {
    if (n < 0 || n < r || r < 0)
      return Mint(0);
    else
      return Fact[n] * Finv[r] * Finv[n - r];
  }
};

// 他のnCr使えない場合試す
Mint com2(int n, int a) {
  Mint x = 1, y = 1;
  REP(i, a) {
    x *= n - i;
    y *= i + 1;
  }
  return x / y;
}

// 1 * 2 * 3 .... * n (mod)
ll modfact(ll n) {
  if (n <= 1)
    return 1;
  return (n * modfact(n - 1)) % MOD;
}

// kが角度だった場合:cos(k * (PI / 180));
// const double PI = acos(-1);のまま使うと円周率(M_PIもあるよ)
const double PI = acos(-1);

// 多次元 vector 生成   例: auto dp = make_vec<long long>(N+1, 5, 5, 5);
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

// 素因数分解
vector<pair<long long, int>> factorize(long long n) {
  vector<pair<long long, int>> res;
  for (long long i = 2; i * i <= n; ++i) {
    if (n % i)
      continue;
    res.emplace_back(i, 0);
    while (n % i == 0) {
      n /= i;
      res.back().second++;
    }
  }
  if (n != 1)
    res.emplace_back(n, 1);
  return res;
}

// 素数判定
bool primejudge(long long a) {
  if (a <= 1)
    return false;
  for (long long i = 2; i * i <= a; i++) {
    if (a % i == 0)
      return false;
  }
  return true;
}

int dy[4] = {0, 1, 0, -1}, dx[4] = {1, 0, -1, 0};
vector<int> graph[100010];

// using mint = Fp<MOD>;

int main() {
  int N, K;
  cin >> N >> K;
  vector<PII> v(K);
  for (int i = 0; i < K; ++i)
    cin >> v[i].first >> v[i].second;

  vector<Mint> dp(N, 0), sdp(N + 1, 0);
  dp[0] = 1, sdp[1] = 1;
  for (int n = 1; n < N; ++n) {
    for (auto p : v) {
      int left = max(0, n - p.second);
      int right = max(0, n - p.first + 1);
      dp[n] += sdp[right] - sdp[left];
    }
    sdp[n + 1] = sdp[n] + dp[n];
  }
  cout << dp[N - 1].val % MOD << endl;
}


#include <bits/stdc++.h>

#define f(i, a, b) for (ll i = a; i < (ll)b; i++)
#define af(i, a, b) for (ll i = a; i >= b; i--)
#define rep(i, a, b, k) for (ll i = a; i < b; i += k)
#define arep(i, a, b, k) for (ll i = a; i >= b; i -= k)
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort(a.begin(), a.end())
#define fastio                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL)
#define inter                                                                  \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0)

// policy-based

using namespace std;

typedef long long ll; // int or long long
typedef long double ld;
typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;

const ll MAX = 2e5 + 1;
const ll inf = 1e9;
const ll mod = 998244353;

ll tree[MAX * 2];

ll l[20], r[20], n, k;

void update(ll l, ll r, ll v) {
  for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
    if (l & 1)
      (tree[l++] += v) %= mod;
    if (r & 1)
      (tree[--r] += v) %= mod;
  }
}

ll query(ll x) {
  ll ans = 0;
  x += n;
  while (x)
    (ans += tree[x]) %= mod, x >>= 1;
  return ans;
}

int main() {
  fastio;
  cin >> n >> k;
  f(i, 0, k) cin >> l[i] >> r[i];
  update(0, 1, 1);
  f(i, 0, n) {
    ll aux = query(i);
    f(j, 0, k) update(i + l[j], i + r[j] + 1, aux);
  }
  cout << query(n - 1) << endl;
  return 0;
}

#include <bits/stdc++.h>

#define f(i, a, b) for (ll i = a; i < (ll)b; i++)
#define af(i, a, b) for (ll i = a; i >= b; i--)
#define rep(i, a, b, k) for (ll i = a; i < b; i += k)
#define arep(i, a, b, k) for (ll i = a; i >= b; i -= k)
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort(a.begin(), a.end())
#define fastio                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL)
#define inter                                                                  \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0)

// policy-based

using namespace std;

typedef long long ll; // int or long long
typedef long double ld;
typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;

const ll MAX = 2e6 + 1;
const ll inf = 1e9;
const ll mod = 998244353;

ll tree[MAX * 2];

ll l[20], r[20], n, k;

void update(ll l, ll r, ll v) {
  for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
    if (l & 1)
      (tree[l++] += v) %= mod;
    if (r & 1)
      (tree[--r] += v) %= mod;
  }
}

ll query(ll x) {
  ll ans = 0;
  x += n;
  while (x)
    (ans += tree[x]) %= mod, x >>= 1;
  return ans;
}

int main() {
  fastio;
  cin >> n >> k;
  f(i, 0, k) cin >> l[i] >> r[i];
  update(0, 1, 1);
  f(i, 0, n) {
    ll aux = query(i);
    f(j, 0, k) update(i + l[j], i + r[j] + 1, aux);
  }
  cout << query(n - 1) << endl;
  return 0;
}


#include <bits/stdc++.h>
#include <iostream>
typedef long long ll;
typedef unsigned int ui;
#define infin (ll)(998244353)
using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  int l, r;
  vector<ll> dp(n + 1, 0); // 0 to n
  vector<pair<int, int>> v;
  for (int j = 0; j < k; j++) {
    cin >> l >> r;
    v.push_back({l, r});
  }
  dp[0] = 1;
  ;
  dp[1] = 1;
  sort(v.begin(), v.end());
  for (int i = 2; i <= n; i++) {
    for (auto x : v) {
      int e = 0;
      for (int j = x.first; j <= x.second; j++) {
        if (j >= i) {
          e = 1;
          break;
        } else {
          dp[i] = (dp[i] + dp[i - j]) % infin;
        }
      }
      if (e == 1)
        break;
    }
  }
  cout << dp[n] << endl;
}

#include <bits/stdc++.h>
#include <iostream>
typedef long long ll;
typedef unsigned int ui;
#define infin (ll)(998244353)
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  int l, r;
  vector<ll> dp(n + 1, 0); // 0 to n
  vector<pair<int, int>> v;
  for (int j = 0; j < k; j++) {
    cin >> l >> r;
    v.push_back({l, r});
  }
  dp[0] = 1;
  ;
  dp[1] = 1;
  sort(v.begin(), v.end());
  auto z = v.begin();
  if ((*z).first == 1)
    dp[2] = 1;
  else
    dp[2] = 0;
  for (int i = 3; i <= n; i++) {
    dp[i] = dp[i - 1];
    for (auto x : v) {
      if (i > x.first)
        dp[i] += dp[i - x.first];
      else
        break;
      if (i - 1 > x.second) {
        dp[i] -= dp[i - 1 - x.second];
        if (dp[i] < 0)
          dp[i] += infin;
      }
    }
    dp[i] = (dp[i]) % infin;
  }
  cout << dp[n] << endl;
}


#include <bits/stdc++.h>

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

const int MOD = 998244353;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> st;
  for (int i = 0; i < k; i++) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++) {
      st.push_back(j);
    }
  }

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

  for (int i = 2; i <= n; i++) {
    for (auto x : st) {
      if (i - x < 0)
        continue;
      dp[i] = (dp[i] + dp[i - x]) % MOD;
    }
  }

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

#include <bits/stdc++.h>

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

const int MOD = 998244353;

int main() {
  int n, k;
  cin >> n >> k;
  vector<pair<int, int>> ar(k);
  for (int i = 0; i < k; i++) {
    cin >> ar[i].first >> ar[i].second;
  }

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

  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < k; j++) {
      if (i <= ar[j].first) {
        continue;
      } else if (i <= ar[j].second) {
        dp[i] += dp[i - ar[j].first];
      } else {
        dp[i] += dp[i - ar[j].first] - dp[i - ar[j].second - 1];
      }
      dp[i] = (dp[i] + MOD) % MOD;
    }
    if (i != n)
      dp[i] += dp[i - 1];
  }
  cout << dp[n] << '\\n';
}


#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <string>

#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>

#define PI 3.14159265358979323846
#define int64 long long
#define uint64 unsigned long long
#define coutfix(i)                                                             \\
  cout << fixed << setprecision(i) // coutの浮動小数出力の桁数設定
using namespace std;

const int64 mod = 998244353;

int main() {
  int64 nn, kk, ll, rr;
  cin >> nn >> kk;
  vector<pair<int64, int64>> memo(kk);
  for (int64 ii = 0; ii < kk; ii++) {
    cin >> memo[ii].first >> memo[ii].second;
  }
  vector<int64> vv(nn, 0), table(nn, 0);
  vv[0] = 1;
  for (auto ite = memo.begin(); ite != memo.end(); ite++) {
    vv[(*ite).first] += vv[0];
    if ((*ite).second + 1 < nn) {
      vv[(*ite).second + 1] -= vv[0];
    }
  }

  for (int64 ii = 1; ii < nn; ii++) {
    vv[ii] += table[ii - 1];
    if (vv[ii] < 0) {
      vv[ii] += mod;
    }
    vv[ii] %= mod;
    table[ii] = vv[ii];
    for (auto ite = memo.begin(); ite != memo.end(); ite++) {
      if (ii + (*ite).first < nn) {
        vv[ii + (*ite).first] += table[ii];
      }
      if (ii + (*ite).second + 1 < nn) {
        vv[ii + (*ite).second + 1] -= table[ii];
      }
    }
  }

  cout << table[nn - 1] << endl;
  return 0;
}

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <string>

#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>

#define PI 3.14159265358979323846
#define int64 long long
#define uint64 unsigned long long
#define coutfix(i)                                                             \\
  cout << fixed << setprecision(i) // coutの浮動小数出力の桁数設定
using namespace std;

const int64 mod = 998244353;

int main() {
  int64 nn, kk;
  cin >> nn >> kk;
  vector<pair<int64, int64>> memo(kk);
  for (int64 ii = 0; ii < kk; ii++) {
    cin >> memo[ii].first >> memo[ii].second;
  }
  vector<int64> vv(3 * nn, 0), table(3 * nn, 0);
  vv[0] = 1;
  for (auto ite = memo.begin(); ite != memo.end(); ite++) {
    vv[(*ite).first] += vv[0];
    if ((*ite).second + 1 < nn) {
      vv[(*ite).second + 1] -= vv[0];
    }
  }

  for (int64 ii = 1; ii < nn; ii++) {
    vv[ii] += table[ii - 1];
    while (vv[ii] < 0) {
      vv[ii] += mod;
    }
    vv[ii] %= mod;
    table[ii] = vv[ii];
    for (auto ite = memo.begin(); ite != memo.end(); ite++) {
      if (ii + (*ite).first < nn) {
        vv[ii + (*ite).first] += table[ii];
        vv[ii + (*ite).first] %= mod;
      }
      if (ii + (*ite).second + 1 < nn) {
        vv[ii + (*ite).second + 1] -= table[ii];
        while (vv[ii + (*ite).second + 1] < 0) {
          vv[ii + (*ite).second + 1] += mod;
        }
        vv[ii + (*ite).second + 1] %= mod;
      }
    }
  }

  cout << table[nn - 1] << endl;
  return 0;
}


#include <bits/stdc++.h>

#define FAST_IO ios_base::sync_with_stdio(false), cin.tie(nullptr)
#define setIO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)
#define trav(e, x) for (const auto &(e) : (x))
#define pb(x) push_back(x)
#define eb(x...) emplace_back(x)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define lc(i) 2 * i
#define rc(i) 2 * i + 1
// #define int long long
using namespace std;
using ii = pair<int, int>;
using vi = vector<int>;
using vb = vector<bool>;
using vii = vector<ii>;
using vivi = vector<vi>;

const int N = 2e5 + 5, MOD = 998244353, INF = 1e9 + 5;

int add(int x, int y) { return ((x % MOD) + (y % MOD)) % MOD; }

struct SegmentTree {
  int n;
  vector<int> t, lazy;

  void init(int x) {
    n = x;
    t.assign(n, 0);
    lazy.assign(4 * n, 0);
  }

  int merge(int x, int y) { return add(x, y); }

  void push(int i, int l, int r) {
    if (lazy[i] != 0) {
      t[i] = add(t[i], lazy[i] * (r - l + 1));
      if (l != r) {
        lazy[lc(i)] = add(lazy[i], lazy[lc(i)]);
        lazy[rc(i)] = add(lazy[i], lazy[rc(i)]);
      }
      lazy[i] = 0;
    }
  }

  void modify(int i, int l, int r, int ql, int qr, int val) {
    push(i, l, r);
    if (l > qr || r < ql)
      return;
    if (l >= ql && r <= qr) {
      lazy[i] = add(lazy[i], val);
      push(i, l, r);
      return;
    }
    int mid = (l + r) / 2;
    modify(lc(i), l, mid, ql, qr, val);
    modify(rc(i), mid + 1, r, ql, qr, val);
    t[i] = merge(t[lc(i)], t[rc(i)]);
  }

  int query(int i, int l, int r, int ql, int qr) {
    push(i, l, r);
    if (l > qr || r < ql)
      return 0;
    if (l >= ql && r <= qr)
      return t[i];
    int mid = (l + r) / 2;
    int resL = query(lc(i), l, mid, ql, qr);
    int resR = query(rc(i), mid + 1, r, ql, qr);
    return merge(resL, resR);
  }

  void modify(int l, int r, int val) { modify(1, 0, n - 1, l, r, val); }

  int query(int l, int r) { return query(1, 0, n - 1, l, r); }
};

signed main() {
  FAST_IO;
  //    setIO("input.txt", "output.txt");

  int n, m;
  cin >> n >> m;
  vii segments;
  while (m--) {
    int l, r;
    cin >> l >> r;
    segments.eb(l, r);
  }
  SegmentTree seg;
  seg.init(n);
  seg.modify(1, 1, 1);
  for (int i = 1; i <= n; i++)
    for (const auto &[l, r] : segments)
      seg.modify(i + l, i + r, seg.query(i, i));
  cout << seg.query(n, n);
}

#include <bits/stdc++.h>

#define FAST_IO ios_base::sync_with_stdio(false), cin.tie(nullptr)
#define setIO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)
#define trav(e, x) for (const auto &(e) : (x))
#define pb(x) push_back(x)
#define eb(x...) emplace_back(x)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define lc(i) 2 * i
#define rc(i) 2 * i + 1
// #define int long long
using namespace std;
using ii = pair<int, int>;
using vi = vector<int>;
using vb = vector<bool>;
using vii = vector<ii>;
using vivi = vector<vi>;

const int N = 2e5 + 5, MOD = 998244353, INF = 1e9 + 5;

int add(int x, int y) { return (((x + MOD) % MOD) + ((y + MOD) % MOD)) % MOD; }

signed main() {
  FAST_IO;
  //    setIO("input.txt", "output.txt");

  int n, m;
  cin >> n >> m;
  vii segments;
  while (m--) {
    int l, r;
    cin >> l >> r;
    segments.eb(l, r);
  }
  vi dp(n + 2, 0), delta(n + 2, 0);
  dp[1] = 1;
  for (int i = 1; i <= n; i++) {
    delta[i] = add(delta[i], delta[i - 1]);
    dp[i] = add(dp[i], delta[i]);
    for (const auto &[l, r] : segments) {
      if (i + l > n)
        continue;
      int x = min(i + l, n), y = min(i + r, n);
      delta[x] = add(delta[x], dp[i]);
      delta[y + 1] = add(delta[y + 1], -dp[i]);
    }
  }
  cout << dp[n];
}


#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define int long long
#define double long double
#define rep(i, n) for (int i = 0; i < n; i++)
#define srep(i, n, m) for (int i = n; i < m; i++)
#define elif else if
#define pi 3.141592653589793
#define prique priority_queue
constexpr auto mod = 1000000007;
using namespace std;
int gcd(int a, int b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
int lcm(int a, int b) { return a * b / gcd(a, b); }
bool prime(int n) {
  int cnt = 0;
  for (int i = 1; i <= sqrt(n); i++) {
    if (n % 1 == 0)
      cnt++;
  }
  if (cnt != 1)
    return false;
  else
    return n != 1;
}
struct UnionFind {
  vector<int> r;
  UnionFind(int N) { r = vector<int>(N, -1); }
  int root(int x) {
    if (r[x] < 0)
      return x;
    return r[x] = root(r[x]);
  }
  bool unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y)
      return false;
    if (r[x] > r[y])
      swap(x, y);
    r[x] += r[y];
    r[y] = x;
    return true;
  }
  int size(int x) { return -r[root(x)]; }
};
vector<int> v;
int n, m, cnt = 0, ans = 0, aa[220000];
pair<int, int> pp[220000];
string s, ss[220000];
queue<int> que;
signed main() {
  cin >> n >> m;
  rep(i, m) { cin >> pp[i].first >> pp[i].second; }
  sort(pp, pp + m);
  aa[1] = 1;
  rep(i, n) {
    if (aa[i + 1] == 0) {
      continue;
    }
    rep(j, m) {
      for (int k = pp[j].first; k < min(pp[j].second + 1, n - i); k++) {
        aa[i + 1 + k] += aa[i + 1];
        aa[i + 1 + k] %= 998244353;
      }
    }
  }
  cout << aa[n];
}

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define int long long
#define double long double
#define rep(i, n) for (int i = 0; i < n; i++)
#define srep(i, n, m) for (int i = n; i < m; i++)
#define elif else if
#define pi 3.141592653589793
#define prique priority_queue
constexpr auto mod = 1000000007;
using namespace std;
int gcd(int a, int b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
int lcm(int a, int b) { return a * b / gcd(a, b); }
bool prime(int n) {
  int cnt = 0;
  for (int i = 1; i <= sqrt(n); i++) {
    if (n % 1 == 0)
      cnt++;
  }
  if (cnt != 1)
    return false;
  else
    return n != 1;
}
struct UnionFind {
  vector<int> r;
  UnionFind(int N) { r = vector<int>(N, -1); }
  int root(int x) {
    if (r[x] < 0)
      return x;
    return r[x] = root(r[x]);
  }
  bool unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y)
      return false;
    if (r[x] > r[y])
      swap(x, y);
    r[x] += r[y];
    r[y] = x;
    return true;
  }
  int size(int x) { return -r[root(x)]; }
};
vector<int> v;
int n, m, cnt = 0, ans = 0, aa[220000], ab[220000];
pair<int, int> pp[220000];
string s, ss[220000];
queue<int> que;
signed main() {
  cin >> n >> m;
  rep(i, m) { cin >> pp[i].first >> pp[i].second; }
  sort(pp, pp + m);
  aa[1] = 1;
  ab[1] = 1;
  for (int i = 2; i < n + 1; i++) {
    rep(j, m) {
      if (pp[j].first > i - 1) {
        break;
      }
      if (ab[i - pp[j].first] < ab[i - pp[j].second - 1])
        aa[i] += ab[i - pp[j].first] - ab[i - pp[j].second - 1] + 998244353;
      else
        aa[i] += ab[i - pp[j].first] - ab[i - pp[j].second - 1];
      aa[i] %= 998244353;
    }
    ab[i] = aa[i] + ab[i - 1];
  }
  cout << aa[n];
}


#include <bits/stdc++.h>

#define nl '\\n'

using namespace std;

typedef long long ll;

void solve() {
  int N, K;
  cin >> N >> K;
  vector<pair<int, int>> range(K);
  for (int i = 0; i < K; i++)
    cin >> range[i].first >> range[i].second;
  const int MOD = 998244353;

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

  cout << dp[N];
}

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

  // int t;
  // cin >> t;
  // while (t--) {
  solve();
  cout << nl;
  // }

  return 0;
}

#include <bits/stdc++.h>

#define nl '\\n'

using namespace std;

typedef long long ll;

void solve() {
  int N, K;
  cin >> N >> K;
  vector<int> L(K), R(K);
  for (int i = 0; i < K; i++)
    cin >> L[i] >> R[i];
  const int MOD = 998244353;

  vector<int> dp(N + 1);
  dp[1] = 1, dp[2] = -1;
  for (int i = 1; i <= N; i++) {
    dp[i] = ((dp[i] + dp[i - 1]) % MOD + MOD) % MOD;
    for (int j = 0; j < K; j++) {
      if (i + L[j] <= N)
        dp[i + L[j]] = ((dp[i + L[j]] + dp[i]) % MOD + MOD) % MOD;
      if (i + R[j] + 1 <= N)
        dp[i + R[j] + 1] = ((dp[i + R[j] + 1] - dp[i]) % MOD + MOD) % MOD;
    }
  }

  cout << dp[N];
}

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

  // int t;
  // cin >> t;
  // while (t--) {
  solve();
  cout << nl;
  // }

  return 0;
}


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

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

  for (int i = 2; i <= n; i++) {
    for (auto itr = s.begin(); itr != s.end(); ++itr) {
      if (i - *itr <= 0)
        break;
      dp[i] += dp[i - *itr];
    }
  }

  cout << dp[n] % mod << endl;
  return 0;
}

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
#define mod 998244353
typedef long long ll;
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 + 1);
  vector<mint> dpsum(n + 1);
  rep(i, k) cin >> l[i] >> r[i];

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

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

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