#include <bits/stdc++.h>
using namespace std;
template <typename T>
bool chmax(T &m, const T &v) {
  if (v > m) return m = v, true;
  return false;
}
template <typename T>
bool chmin(T &m, const T &v) {
  if (v < m) return m = v, true;
  return false;
}
template <typename T>
bool chinc(T &v1, T &v2) {
  if (v1 > v2) return swap(v1, v2), true;
  return false;
}
template <typename T>
bool chdec(T &v1, T &v2) {
  if (v1 < v2) return swap(v1, v2), true;
  return false;
}
namespace fio {
static const char eof = '\xff';
struct Cg {
  inline char operator()() {
    char c = (char)getchar();
    if (c == eof) valid = false;
    return c;
  };
  bool valid = true;
};
struct Cp {
  inline void operator()(int x) { putchar(x); }
};
struct Ce {
  inline void operator()(int x) { putc(x, stderr); }
};
inline bool IS(char x) {
  return x == ' ' || x == '\r' || x == '\n' || x == '\t';
}
template <class T>
struct Fr {
  T P;
  inline Fr &operator,(int &x) {
    x = 0;
    int c = P();
    while ((c < '0' || c > '9') && c != '-') c = P();
    bool h = false;
    if (c == '-') h = true, c = P();
    for (; c >= '0' && c <= '9'; c = P()) x = x * 10 + c - '0';
    if (h) x = -x;
    return *this;
  }
  inline Fr &operator,(long &x) {
    x = 0;
    int c = P();
    while ((c < '0' || c > '9') && c != '-') c = P();
    bool h = false;
    if (c == '-') h = true, c = P();
    for (; c >= '0' && c <= '9'; c = P()) x = x * 10 + c - '0';
    if (h) x = -x;
    return *this;
  }
  inline Fr &operator,(long long &x) {
    x = 0;
    int c = P();
    while ((c < '0' || c > '9') && c != '-') c = P();
    bool h = false;
    if (c == '-') h = true, c = P();
    for (; c >= '0' && c <= '9'; c = P()) x = x * 10 + c - '0';
    if (h) x = -x;
    return *this;
  }
  inline Fr &operator,(unsigned &x) {
    x = 0;
    int c = P();
    while ((c < '0' || c > '9') && c != '-') c = P();
    bool h = false;
    if (c == '-') h = true, c = P();
    for (; c >= '0' && c <= '9'; c = P()) x = x * 10 + c - '0';
    if (h) x = -x;
    return *this;
  }
  inline Fr &operator,(unsigned long &x) {
    x = 0;
    int c = P();
    while ((c < '0' || c > '9') && c != '-') c = P();
    bool h = false;
    if (c == '-') h = true, c = P();
    for (; c >= '0' && c <= '9'; c = P()) x = x * 10 + c - '0';
    if (h) x = -x;
    return *this;
  }
  inline Fr &operator,(unsigned long long &x) {
    x = 0;
    int c = P();
    while ((c < '0' || c > '9') && c != '-') c = P();
    bool h = false;
    if (c == '-') h = true, c = P();
    for (; c >= '0' && c <= '9'; c = P()) x = x * 10 + c - '0';
    if (h) x = -x;
    return *this;
  }
  inline Fr &operator,(float &x) {
    x = 0;
    int c = P();
    while ((c < '0' || c > '9') && c != '-') c = P();
    bool h = false;
    if (c == '-') h = true, c = P();
    for (; c >= '0' && c <= '9'; c = P()) x = x * 10 + c - '0';
    if (c == '.') {
      double u = 0.1;
      for (c = P(); c >= '0' && c <= '9'; c = P(), u *= 0.1) x += u * (c - '0');
    };
    if (h) x = -x;
    return *this;
  }
  inline Fr &operator,(double &x) {
    x = 0;
    int c = P();
    while ((c < '0' || c > '9') && c != '-') c = P();
    bool h = false;
    if (c == '-') h = true, c = P();
    for (; c >= '0' && c <= '9'; c = P()) x = x * 10 + c - '0';
    if (c == '.') {
      double u = 0.1;
      for (c = P(); c >= '0' && c <= '9'; c = P(), u *= 0.1) x += u * (c - '0');
    };
    if (h) x = -x;
    return *this;
  }
  inline Fr &operator,(long double &x) {
    x = 0;
    int c = P();
    while ((c < '0' || c > '9') && c != '-') c = P();
    bool h = false;
    if (c == '-') h = true, c = P();
    for (; c >= '0' && c <= '9'; c = P()) x = x * 10 + c - '0';
    if (c == '.') {
      double u = 0.1;
      for (c = P(); c >= '0' && c <= '9'; c = P(), u *= 0.1) x += u * (c - '0');
    };
    if (h) x = -x;
    return *this;
  }
  inline Fr &operator,(char &x) {
    for (x = P(); IS(x);) x = P();
    return *this;
  }
  inline Fr &operator,(char *s) {
    for (*s = P(); IS(*s) && P.valid;) *s = P();
    for (; !IS(*s) && P.valid;) *++s = P();
    *s = 0;
    return *this;
  }
  inline Fr &operator,(string &s) {
    s.clear();
    char c = P();
    for (; IS(c) && P.valid;) c = P();
    for (; !IS(c) && P.valid;) s.push_back(c), c = P();
    return *this;
  }
  inline operator bool() { return P.valid; }
};
template <class T>
struct Fw {
  T P;
  char B[32];
  inline Fw &operator,(int x) {
    if (x) {
      if (x < 0) P('-'), x = -x;
      int p = 0;
      while (x) B[p++] = x % 10 + '0', x /= 10;
      while (p--) P(B[p]);
    } else
      P('0');
    return *this;
  }
  inline Fw &operator,(long x) {
    if (x) {
      if (x < 0) P('-'), x = -x;
      int p = 0;
      while (x) B[p++] = x % 10 + '0', x /= 10;
      while (p--) P(B[p]);
    } else
      P('0');
    return *this;
  }
  inline Fw &operator,(long long x) {
    if (x) {
      if (x < 0) P('-'), x = -x;
      int p = 0;
      while (x) B[p++] = x % 10 + '0', x /= 10;
      while (p--) P(B[p]);
    } else
      P('0');
    return *this;
  }
  inline Fw &operator,(unsigned x) {
    if (x) {
      if (x < 0) P('-'), x = -x;
      int p = 0;
      while (x) B[p++] = x % 10 + '0', x /= 10;
      while (p--) P(B[p]);
    } else
      P('0');
    return *this;
  }
  inline Fw &operator,(unsigned long x) {
    if (x) {
      if (x < 0) P('-'), x = -x;
      int p = 0;
      while (x) B[p++] = x % 10 + '0', x /= 10;
      while (p--) P(B[p]);
    } else
      P('0');
    return *this;
  }
  inline Fw &operator,(unsigned long long x) {
    if (x) {
      if (x < 0) P('-'), x = -x;
      int p = 0;
      while (x) B[p++] = x % 10 + '0', x /= 10;
      while (p--) P(B[p]);
    } else
      P('0');
    return *this;
  }
  inline Fw &operator()(float g, int d) {
    if (d) {
      double t = 0.5;
      for (int i = d; i--;) t *= 0.1;
      if (g < 0) P('-'), g = -g;
      g += t;
      *this, (long long)(g);
      P('.');
      g -= floor(g);
      while (d--) {
        g *= 10;
        int i = (int)floor(g);
        P(i + '0');
        g -= i;
      }
    } else
      *this, (g > 0 ? (long long)(g + 0.5) : (long long)(g - 0.5));
    return *this;
  }
  inline Fw &operator()(double g, int d) {
    if (d) {
      double t = 0.5;
      for (int i = d; i--;) t *= 0.1;
      if (g < 0) P('-'), g = -g;
      g += t;
      *this, (long long)(g);
      P('.');
      g -= floor(g);
      while (d--) {
        g *= 10;
        int i = (int)floor(g);
        P(i + '0');
        g -= i;
      }
    } else
      *this, (g > 0 ? (long long)(g + 0.5) : (long long)(g - 0.5));
    return *this;
  }
  inline Fw &operator()(long double g, int d) {
    if (d) {
      double t = 0.5;
      for (int i = d; i--;) t *= 0.1;
      if (g < 0) P('-'), g = -g;
      g += t;
      *this, (long long)(g);
      P('.');
      g -= floor(g);
      while (d--) {
        g *= 10;
        int i = (int)floor(g);
        P(i + '0');
        g -= i;
      }
    } else
      *this, (g > 0 ? (long long)(g + 0.5) : (long long)(g - 0.5));
    return *this;
  }
  inline Fw &operator,(char x) {
    P(x);
    return *this;
  }
  typedef basic_ostream<char, char_traits<char> > &OS;
  typedef basic_istream<char, char_traits<char> > &IS;
  inline Fw &operator,(OS &(*func)(OS)) {
    if (func == static_cast<OS &(*)(OS)>(endl<char, char_traits<char> >))
      P('\n');
    return *this;
  }
  inline Fw &operator,(IS &(*func)(IS)) {
    if (func == static_cast<IS &(*)(IS)>(ws<char, char_traits<char> >)) P(' ');
    return *this;
  }
  inline Fw &operator,(const char *s) {
    for (; *s; ++s) P(*s);
    return *this;
  }
  inline Fw &operator,(const string &s) {
    (*this), s.c_str();
    return *this;
  }
  template <class C>
  inline Fw &all(const C &v, char sep = ' ', char nl = '\n') {
    auto it = v.begin();
    for (int i = 0; i < (int)v.size(); ++i, ++it) {
      if (i && sep) P(sep);
      (*this), *it;
    }
    if (nl) P(nl);
    return *this;
  }
  template <class U>
  inline Fw &print(U x) {
    (*this), x;
    P('\n');
    return *this;
  }
  template <class U, class... Us>
  inline Fw &print(U x, Us... args) {
    (*this), x;
    P(' ');
    print(args...);
    return *this;
  }
};
}  // namespace fio
fio::Fr<fio::Cg> fin;
fio::Fw<fio::Cp> fout;
fio::Fw<fio::Ce> ferr;
static inline unsigned all_ones(unsigned x) {
  x |= (x >> 1);
  x |= (x >> 2);
  x |= (x >> 4);
  x |= (x >> 8);
  x |= (x >> 16);
  return x;
}
static inline int floor_log2(unsigned x) {
  int ans = 0;
  while (x >>= 1) ++ans;
  return ans;
}
static inline bool is_pow2(unsigned x) { return !(x & (x - 1)); }
static inline unsigned next_pow2(unsigned x) { return all_ones(x) + 1; }
static inline unsigned ceil_pow2(unsigned x) {
  if (is_pow2(x)) return x;
  return next_pow2(x);
}
static inline int msb32(unsigned int x) {
  x = all_ones(x);
  return x & ~(x >> 1);
}
static inline int lsb32(unsigned int x) { return x & -x; }
template <typename Int>
Int gcd(Int a, Int b) {
  while (a != 0) {
    b %= a;
    if (b == 0) return a;
    a %= b;
  }
  return b;
}
template <typename Int, typename RInt = Int>
Int lcm(Int a, Int b) {
  return a / gcd(a, b) * static_cast<RInt>(b);
}
template <typename Int, typename XInt>
Int extended_gcd(Int a, Int b, XInt &x, XInt &y) {
  static_assert(std::numeric_limits<XInt>::is_signed, "x, y must be signed");
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  Int g = extended_gcd(b, a % b, y, x);
  y -= (a / b) * x;
  return g;
}
template <typename Int>
Int mul_mod(Int a, Int b, Int m) {
  static_assert(2 * std::numeric_limits<Int>::digits <=
                    std::numeric_limits<int64_t>::digits,
                "multiplication will overflow!");
  int64_t p = a;
  p = (p * b) % m;
  return (Int)p;
}
template <>
int64_t mul_mod<int64_t>(int64_t a, int64_t b, int64_t m) {
  __int128_t p = __int128_t(a) * b;
  return (int64_t)(p % m);
}
template <typename Int, typename PInt>
Int pow_mod(Int a, PInt p, Int m) {
  Int r;
  a %= m;
  for (r = 1; p; p >>= 1) {
    if (p & 1) r = mul_mod(r, a, m);
    a = mul_mod(a, a, m);
  }
  return r;
}
template <typename Int, typename XInt = typename std::make_signed<Int>::type>
Int inv_mod(Int a, Int m) {
  XInt x, y;
  extended_gcd(a, m, x, y);
  if (x < 0) return x + m;
  return x;
}
template <typename Int>
Int addx_mod(Int u, Int v, Int m) {
  Int r = u + v;
  if (r >= m) r -= m;
  return r;
}
template <typename Int>
Int subx_mod(Int u, Int v, Int m) {
  Int r = u - v;
  if (r < 0) r += m;
  return r;
}
template <typename Int>
Int div_mod(Int u, Int v, Int m) {
  Int g = gcd(v, m);
  assert(u % g == 0);
  Int mm = m / g;
  return mul_mod(u / g, inv_mod(v / g, mm), mm);
}
template <typename Int>
Int div_pos_r(Int a, Int b, Int &r) {
  Int q = a / b;
  r = a % b;
  if (r < 0) {
    if (b < 0)
      q += 1, r -= b;
    else
      q -= 1, r += b;
  }
  return q;
}
template <typename Int>
Int coprime_div(Int a, Int b) {
  while (b != 1) {
    while (a % b == 0) a /= b;
    b = gcd(a, b);
  }
  return a;
}
template <typename T>
struct binary_plus {
  T identity() const { return T(); }
  T operator()(const T &t1, const T &t2) const { return t1 + t2; }
  T negate(const T &t) { return -t; }
};
template <typename T, T MOD>
struct modular_plus {
  T identity() const { return T(); }
  T operator()(const T &t1, const T &t2) const { return (t1 + t2) % MOD; }
  T negate(const T &t) { return (MOD - t) % MOD; }
};
template <typename T, T MOD, typename TT = int64_t>
struct modular_times {
  T identity() const { return 1; }
  T operator()(const T &t1, const T &t2) const { return mul_mod(t1, t2, MOD); }
  T negate(const T &t) { return inv_mod(t, MOD); }
};
template <typename T>
struct binary_xor {
  T identity() const { return T(); }
  T operator()(const T &t1, const T &t2) const { return t1 ^ t2; }
  T negate(const T &t) { return t; }
};
template <typename T>
struct binary_max {
  T identity() const { return std::numeric_limits<T>::min(); }
  T operator()(const T &t1, const T &t2) const { return std::max(t1, t2); }
};
template <typename T>
struct binary_min {
  T identity() const { return std::numeric_limits<T>::max(); }
  T operator()(const T &t1, const T &t2) const { return std::min(t1, t2); }
};
template <typename T, typename Op = binary_plus<T>, bool flavour_one = true>
struct segtree;
template <typename T, typename Op>
struct segtree<T, Op, true> {
  Op op;
  std::vector<T> vec;
  int size;
  int offset;
  segtree(int n) {
    size = n;
    offset = ceil_pow2(n);
    vec.resize(size + offset + 1, op.identity());
  }
  T &operator[](int i) { return vec[offset + i]; }
  void rebuild() {
    for (int i = (offset + size - 1) / 2; i > 0; --i)
      vec[i] = op(vec[i + i], vec[i + i + 1]);
  }
  void increase_element(int p, const T &n) {
    for (p += offset; p; p >>= 1) vec[p] = op(n, vec[p]);
  }
  void update_element(int p, const T &n) {
    p += offset;
    vec[p] = n;
    while (p >>= 1) vec[p] = op(vec[p + p], vec[p + p + 1]);
  }
  T query_range(int s, int t) { return query_include(s, t - 1); }
  T query_include(int s, int t) {
    if (s > t) return op.identity();
    s += offset;
    t += offset;
    T left_acc = vec[s];
    if (s == t) return left_acc;
    T right_acc = vec[t];
    for (; s ^ t ^ 1; s >>= 1, t >>= 1) {
      if (~s & 1) left_acc = op(left_acc, vec[s ^ 1]);
      if (t & 1) right_acc = op(vec[t ^ 1], right_acc);
    }
    return op(left_acc, right_acc);
  }
};
template <typename T, typename Op>
struct segtree<T, Op, false> {
  Op op;
  std::vector<T> vec;
  int size;
  int offset;
  segtree(int n) {
    size = n;
    offset = ceil_pow2(n);
    vec.resize(size + offset + 1, op.identity());
  }
  T &operator[](int i) { return vec[offset + i]; }
  T query_element(int p) {
    T ret = op.identity();
    for (p += offset; p; p >>= 1) ret = op(vec[p], ret);
    return ret;
  }
  void increase_range(int s, int t, const T &inc) {
    return increase_include(s, t - 1, inc);
  }
  void increase_include(int s, int t, const T &inc) {
    if (s > t) return;
    s += offset;
    t += offset;
    vec[s] = op(inc, vec[s]);
    if (s == t) return;
    vec[t] = op(inc, vec[t]);
    for (; s ^ t ^ 1; s >>= 1, t >>= 1) {
      if (~s & 1) vec[s ^ 1] = op(inc, vec[s ^ 1]);
      if (t & 1) vec[t ^ 1] = op(inc, vec[t ^ 1]);
    }
    return;
  }
  void flatten() {
    for (int i = 1; i < offset; ++i) {
      if (i + i < offset + size) {
        vec[i + i] = op(vec[i], vec[i + i]);
        vec[i + i + 1] = op(vec[i], vec[i + i + 1]);
      } else
        break;
      vec[i] = op.identity();
    }
  }
};
template <int32_t MOD>
struct mod_int {
  mod_int() : v(0) {}
  mod_int(int32_t in) : v(in) { fixup(); }
  void fixup() {
    if (v < 0 || v >= MOD) {
      v = v % MOD;
      if (v < 0) v += MOD;
    }
  }
  explicit operator int() const { return v; }
  mod_int &operator+=(const mod_int &that) {
    (v) = addx_mod((v), (that.v), MOD);
    return *this;
  }
  mod_int operator+(const mod_int &that) const {
    return {addx_mod((v), (that.v), MOD)};
  }
  mod_int &operator-=(const mod_int &that) {
    (v) = subx_mod((v), (that.v), MOD);
    return *this;
  }
  mod_int operator-(const mod_int &that) const {
    return {subx_mod((v), (that.v), MOD)};
  }
  mod_int &operator*=(const mod_int &that) {
    (v) = mul_mod((v), (that.v), MOD);
    return *this;
  }
  mod_int operator*(const mod_int &that) const {
    return {mul_mod((v), (that.v), MOD)};
  }
  mod_int &operator/=(const mod_int &that) {
    (v) = div_mod((v), (that.v), MOD);
    return *this;
  }
  mod_int operator/(const mod_int &that) const {
    return {div_mod((v), (that.v), MOD)};
  }
  int32_t v;
};
constexpr int MOD = 998244353;
constexpr int maxn = 100005;
int dp[maxn];
int main() {
  int N, K;
  fin, N, K;
  vector<pair<int, int> > intv;
  for (int i = 0, iend = K; i < iend; i++) {
    int L, R;
    fin, L, R;
    intv.push_back({L, R});
  }
  segtree<mod_int<MOD> > segtree(maxn);
  segtree.increase_element(1, 1);
  for (int i = 2, iend = N; i <= iend; i++) {
    mod_int<MOD> sum = 0;
    for (pair<int, int> lr : intv) {
      int L = i - lr.second;
      int R = i - lr.first;
      if (R < 1) continue;
      chmax(L, 1);
      sum += segtree.query_include(L, R);
    }
    segtree.increase_element(i, sum);
  }
  fout, segtree.query_include(N, N).v, '\n';
  return 0;
}
