#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
#pragma GCC optimize("O3")
using namespace std;

#if __cplusplus < 201103L
#error C++11 or higher expected.
#endif
#define CPPV (__cplusplus / 100 % 100) // C++ Version

// define
#define endl "\n"
#ifdef LOCAL
#define lout cerr
#else
ostream devnull(0);
#define lout devnull
#endif
#define dump(x) lout << #x << " = " << (x) << endl;

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

// rep
// Inspired by:
// https://github.com/kurokoji/.cpp-Template/blob/master/template/template2.cpp
#define GET_MACRO(_1, _2, _3, _4, NAME, ...) NAME
#define rep(...)                                 \
  GET_MACRO(__VA_ARGS__, rep4, rep3, rep2, rep1) \
  (__VA_ARGS__)
#define rep1(n) rep2(_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, n) rep4(i, a, n, 1)
#define rep4(i, a, n, d) rep5(i, a, n, d, <)
#define rep5(i, a, n, d, o) \
  for (auto i = decltype(n)(a), i##_len = (n); i o i##_len; i += (d))

#define rrep(...)                                    \
  GET_MACRO(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1) \
  (__VA_ARGS__)
#define rrep1(a) rrep2(_, a)
#define rrep2(i, a) rrep3(i, a, 0)
#define rrep3(i, a, n) rrep4(i, a, n, -1)
#define rrep4(i, a, n, d) rep5(i, (a)-1, n, d, >=)

#define repc(...)                                    \
  GET_MACRO(__VA_ARGS__, repc4, repc3, repc2, repc1) \
  (__VA_ARGS__)
#define repc1(n) repc2(_, n)
#define repc2(i, n) repc3(i, 0, n)
#define repc3(i, a, n) repc4(i, a, n, 1)
#define repc4(i, a, n, d) rep5(i, a, n, d, <=)

// alias
using ll = long long;
using lint = long long;

// func
template <class C>
void vcin(C &c)
{
  for (auto &&a : c)
  {
    cin >> a;
  }
}
template <class C, class D>
void vcin(C &c, D &d)
{
  for (auto it1 = c.begin(), it2 = d.begin(); it1 != c.end() && it2 != d.end();
       it1++, it2++)
  {
    cin >> *it1 >> *it2;
  }
}
template <class C>
void vcout(const C &c, const string delimiter = " ")
{
  for (auto it = c.begin(); it != c.end(); it++)
  {
    if (it != c.begin())
      cout << delimiter;
    cout << *it;
  }
}
template <class T = int>
inline T input()
{
  T x;
  cin >> x;
  return (x);
}
template <typename T>
inline void chmax(T &x, const T y)
{
  if (x < y)
    x = y;
}
template <typename T>
inline void chmin(T &x, const T y)
{
  if (x > y)
    x = y;
}

#if CPPV >= 14
// http://beet-aizu.hatenablog.com/entry/2018/04/08/145516
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
  return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v)
{
  t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v)
{
  for (auto &e : t)
    fill_v(e, v);
}
#endif

constexpr int INF = 1 << 24;
constexpr lint LINF = 1LL << 48;

inline lint bit(int n)
{
  return 1LL << n;
}

inline bool bitof(lint n, int i)
{
  return (n >> i) & 1;
}

template <typename T>
inline bool between(T a, T x, T b)
{
  return a <= x && x <= b;
}

const int MOD = 998244353;
// https://algo-logic.info/segment-tree/#toc_id_3

/* RMQ：[0,n-1] について、区間ごとの最小値を管理する構造体
    update(a,b,x): 区間[a,b) の要素を x に更新。O(log(n))
    query(a,b): [a,b) での最小の要素を取得。O(log(n))
*/
template <typename T>
struct RMQ
{
  const T INF = numeric_limits<T>::max();
  // const T INF = T("1000000000000000000000000000000000000000");
  int n;
  vector<T> dat, lazy;
  RMQ(int n_) : n(), dat(n_ * 4, INF), lazy(n_ * 4, INF)
  {
    int x = 1;
    while (n_ > x)
      x *= 2;
    n = x;
  }
  /* lazy eval */
  void eval(int k)
  {
    if (lazy[k] == INF)
      return; // 更新するものが無ければ終了
    if (k < n - 1)
    { // 葉でなければ子に伝搬
      lazy[k * 2 + 1] = lazy[k];
      lazy[k * 2 + 2] = lazy[k];
    }
    // 自身を更新
    dat[k] += lazy[k];
    lazy[k] = INF;
  }
  void update(int a, int b, T x, int k, int l, int r)
  {
    eval(k);
    if (a <= l && r <= b)
    { // 完全に内側の時
      lazy[k] += x;
      eval(k);
    }
    else if (a < r && l < b)
    {                                             // 一部区間が被る時
      update(a, b, x, k * 2 + 1, l, (l + r) / 2); // 左の子
      update(a, b, x, k * 2 + 2, (l + r) / 2, r); // 右の子
      dat[k] = dat[k * 2 + 1] + dat[k * 2 + 2];
    }
  }
  void update(int a, int b, T x) { update(a, b, x, 0, 0, n); }
  T query_sub(int a, int b, int k, int l, int r)
  {
    eval(k);
    if (r <= a || b <= l)
    { // 完全に外側の時
      return INF;
    }
    else if (a <= l && r <= b)
    { // 完全に内側の時
      return dat[k];
    }
    else
    { // 一部区間が被る時
      T vl = query_sub(a, b, k * 2 + 1, l, (l + r) / 2);
      T vr = query_sub(a, b, k * 2 + 2, (l + r) / 2, r);
      return vl + vr;
    }
  }
  T query(int a, int b) { return query_sub(a, b, 0, 0, n); }
  /* debug */
  inline T operator[](int a) { return query(a, a + 1); }
  void print()
  {
    for (int i = 0; i < 2 * n - 1; ++i)
    {
      cout << (*this)[i];
      if (i != n)
        cout << ",";
    }
    cout << endl;
  }
};

void solve();

signed main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);

  solve();

  return 0;
}

void solve()
{

  int n, k;
  cin >> n >> k;
  vector<int> l(k), r(k);
  rep(j, k)
  {
    cin >> l[j] >> r[j];
  }

  RMQ<mp::cpp_int> rmq(n);

  rmq.update(0, 1, 1);

#ifdef LOCAL
  rep(i, n)
  {
    lout << rmq.query(i, i + 1) << " ";
  }
  lout << endl;
#endif

  rep(i, n)
  {
    rep(j, k)
    {
      rmq.update(i + l[j], i + r[j] + 1, rmq.query(i, i + 1));
    }
  }

#ifdef LOCAL
  rep(i, n)
  {
    lout << rmq.query(i, i + 1) << " ";
  }
  lout << endl;
#endif

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