#include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << '{';
  string sep;
  for (const auto &x : v) os << sep << x, sep = ", ";
  return os << '}';
}
template <typename T, size_t size>
ostream &operator<<(ostream &os, const array<T, size> &arr) {
  os << '{';
  string sep;
  for (const auto &x : arr) os << sep << x, sep = ", ";
  return os << '}';
}
template <typename A, typename B>
ostream &operator<<(ostream &os, const pair<A, B> &p) {
  return os << '(' << p.first << ", " << p.second << ')';
}
void dbg_out() { cerr << endl; }
template <typename Head, typename... Tail>
void dbg_out(Head H, Tail... T) {
  cerr << ' ' << H;
  dbg_out(T...);
}
template <const int &MOD>
struct _m_int {
  int val;
  _m_int(int64_t v = 0) {
    if (v < 0) v = v % MOD + MOD;
    if (v >= MOD) v %= MOD;
    val = int(v);
  }
  _m_int(uint64_t v) {
    if (v >= MOD) v %= MOD;
    val = int(v);
  }
  _m_int(int v) : _m_int(int64_t(v)) {}
  _m_int(unsigned v) : _m_int(uint64_t(v)) {}
  static int inv_mod(int a, int m = MOD) {
    int g = m, r = a, x = 0, y = 1;
    while (r != 0) {
      int q = g / r;
      g %= r;
      swap(g, r);
      x -= q * y;
      swap(x, y);
    }
    return x < 0 ? x + m : x;
  }
  explicit operator int() const { return val; }
  explicit operator unsigned() const { return val; }
  explicit operator int64_t() const { return val; }
  explicit operator uint64_t() const { return val; }
  explicit operator double() const { return val; }
  explicit operator long double() const { return val; }
  _m_int &operator+=(const _m_int &other) {
    val -= MOD - other.val;
    if (val < 0) val += MOD;
    return *this;
  }
  _m_int &operator-=(const _m_int &other) {
    val -= other.val;
    if (val < 0) val += MOD;
    return *this;
  }
  static unsigned fast_mod(uint64_t x, unsigned m = MOD) {
    return unsigned(x % m);
    unsigned x_high = unsigned(x >> 32), x_low = unsigned(x);
    unsigned quot, rem;
    asm("divl %4\n" : "=a"(quot), "=d"(rem) : "d"(x_high), "a"(x_low), "r"(m));
    return rem;
  }
  _m_int &operator*=(const _m_int &other) {
    val = fast_mod(uint64_t(val) * other.val);
    return *this;
  }
  _m_int &operator/=(const _m_int &other) { return *this *= other.inv(); }
  friend _m_int operator+(const _m_int &a, const _m_int &b) {
    return _m_int(a) += b;
  }
  friend _m_int operator-(const _m_int &a, const _m_int &b) {
    return _m_int(a) -= b;
  }
  friend _m_int operator*(const _m_int &a, const _m_int &b) {
    return _m_int(a) *= b;
  }
  friend _m_int operator/(const _m_int &a, const _m_int &b) {
    return _m_int(a) /= b;
  }
  _m_int &operator++() {
    val = val == MOD - 1 ? 0 : val + 1;
    return *this;
  }
  _m_int &operator--() {
    val = val == 0 ? MOD - 1 : val - 1;
    return *this;
  }
  _m_int operator++(int) {
    _m_int before = *this;
    ++*this;
    return before;
  }
  _m_int operator--(int) {
    _m_int before = *this;
    --*this;
    return before;
  }
  _m_int operator-() const { return val == 0 ? 0 : MOD - val; }
  friend bool operator==(const _m_int &a, const _m_int &b) {
    return a.val == b.val;
  }
  friend bool operator!=(const _m_int &a, const _m_int &b) {
    return a.val != b.val;
  }
  friend bool operator<(const _m_int &a, const _m_int &b) {
    return a.val < b.val;
  }
  friend bool operator>(const _m_int &a, const _m_int &b) {
    return a.val > b.val;
  }
  friend bool operator<=(const _m_int &a, const _m_int &b) {
    return a.val <= b.val;
  }
  friend bool operator>=(const _m_int &a, const _m_int &b) {
    return a.val >= b.val;
  }
  _m_int inv() const { return inv_mod(val); }
  _m_int pow(int64_t p) const {
    if (p < 0) return inv().pow(-p);
    _m_int a = *this, result = 1;
    while (p > 0) {
      if (p & 1) result *= a;
      p >>= 1;
      if (p > 0) a *= a;
    }
    return result;
  }
  friend ostream &operator<<(ostream &os, const _m_int &m) {
    return os << m.val;
  }
};
extern const int MOD = 998244353;
using mod_int = _m_int<MOD>;
template <typename T>
struct interval_union {
  struct segment {
    T start, end;
    bool operator<(const segment &other) const { return start < other.start; }
  };
  set<segment> segments;
  T total_length = 0;
  int size() const { return segments.size(); }
  typename set<segment>::iterator prev(
      typename set<segment>::iterator it) const {
    return it == segments.begin() ? it : --it;
  }
  typename set<segment>::iterator next(
      typename set<segment>::iterator it) const {
    return it == segments.end() ? it : ++it;
  }
  bool overlaps(const segment &seg1, const segment &seg2) const {
    return max(seg1.start, seg2.start) <= min(seg1.end, seg2.end);
  }
  bool insert(segment seg) {
    if (seg.start == seg.end) return false;
    assert(seg.start < seg.end);
    if (segments.empty()) {
      segments.insert(seg);
      total_length += seg.end - seg.start;
      return true;
    }
    auto it = prev(segments.upper_bound(seg));
    assert(it != segments.end());
    if (it->start <= seg.start && seg.end <= it->end) return false;
    if (!overlaps(seg, *it)) it++;
    while (it != segments.end() && overlaps(seg, *it)) {
      total_length -= it->end - it->start;
      seg.start = min(seg.start, it->start);
      seg.end = max(seg.end, it->end);
      it = segments.erase(it);
    }
    segments.insert(it, seg);
    total_length += seg.end - seg.start;
    return true;
  }
  bool insert(T start, T end) { return insert({start, end}); }
};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, K;
  cin >> N >> K;
  interval_union<int> segs;
  for (int i = 0; i < K; i++) {
    int L, R;
    cin >> L >> R;
    R++;
    segs.insert(L, R);
  }
  vector<array<int, 2>> ranges;
  for (auto &seg : segs.segments) ranges.push_back({seg.start, seg.end});
  vector<mod_int> dp(N, 0);
  vector<mod_int> dp_prefix(N + 1, 0);
  dp[0] = 1;
  dp_prefix[1] = 1;
  for (int i = 1; i < N; i++) {
    for (int k = 0; k < K; k++) {
      int first = ranges[k][0];
      int last = ranges[k][1] - 1;
      dp[i] += dp_prefix[max(i - first + 1, 0)] - dp_prefix[max(i - last, 0)];
    }
    dp_prefix[i + 1] = dp_prefix[i] + dp[i];
  }
  cout << dp[N - 1] << '\n';
}
