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

template<typename T, typename U> void cmax(T &a, U b) { if (a < b) a = b; }
template<typename T, typename U> void cmin(T &a, U b) { if (a > b) a = b; }

template <unsigned int mod> class modint {
private:
  unsigned int v;
  static unsigned int norm(const unsigned int& x) { return x < mod ? x : x - mod; }
  static modint make(const unsigned int& x) { modint m; return m.v = x, m; }
  static modint inv(const modint& x) { return make(inverse(x.v, mod)); }
  static unsigned int inverse(int a, int m) {
    int u[] = {a, 1, 0}, v[] = {m, 0, 1}, t;
    while (*v) {
      t = *u / *v;
      swap(u[0] -= t * v[0], v[0]), swap(u[1] -= t * v[1], v[1]), swap(u[2] -= t * v[2], v[2]);
    }
    return (u[1] % m + m) % m;
  }

public:
  modint() : v{0} {}
  modint(const long val) : v{norm(val % mod + mod)} {}
  modint(const modint<mod>& n) : v{n()} {}
  explicit operator bool() const noexcept { return v != 0; }
  bool operator!() const noexcept { return !static_cast<bool>(*this); }
  modint& operator=(const modint& n) { return v = n(), (*this); }
  modint& operator=(const long val) { return v = norm(val % mod + mod), (*this); }
  modint operator+() const { return *this; }
  modint operator-() const { return v == 0 ? make(0) : make(mod - v); }
  modint operator+(const modint& val) const { return make(norm(v + val())); }
  modint operator-(const modint& val) const { return make(norm(v + mod - val())); }
  modint operator*(const modint& val) const { return make((long)v * val() % mod); }
  modint operator/(const modint& val) const { return *this * inv(val); }
  modint& operator+=(const modint& val) { return *this = *this + val; }
  modint& operator-=(const modint& val) { return *this = *this - val; }
  modint& operator*=(const modint& val) { return *this = *this * val; }
  modint& operator/=(const modint& val) { return *this = *this / val; }
  modint operator+(const long val) const { return modint{v + val}; }
  modint operator-(const long val) const { return modint{v - val}; }
  modint operator*(const long val) const { return modint{(long)(v * (val % mod))}; }
  modint operator/(const long val) const { return modint{(long)v * inv(val)}; }
  modint& operator+=(const long val) { return *this = *this + val; }
  modint& operator-=(const long val) { return *this = *this - val; }
  modint& operator*=(const long val) { return *this = *this * val; }
  modint& operator/=(const long val) { return *this = *this / val; }
  bool operator==(const modint& val) const { return v == val.v; }
  bool operator!=(const modint& val) const { return !(*this == val); }
  bool operator==(const long val) const { return v == norm(val % mod + mod); }
  bool operator!=(const long val) const { return !(*this == val); }
  unsigned int operator()() const { return v; }
  friend modint operator+(const long val, const modint& n) { return n + val; }
  friend modint operator-(const long val, const modint& n) { return modint{val - n()}; }
  friend modint operator*(const long val, const modint& n) { return n * val; }
  friend modint operator/(const long val, const modint& n) { return modint{val} / n; }
  friend bool operator==(const long val, const modint& n) { return n == val; }
  friend bool operator!=(const long val, const modint& n) { return !(val == n); }
  friend istream& operator>>(istream& is, modint& n) {
    unsigned int v;
    return is >> v, n = v, is;
  }
  friend ostream& operator<<(ostream& os, const modint& n) { return (os << n()); }
};

// constexpr int MOD = 1000000007;
constexpr int MOD = 998244353;
using mint = modint<MOD>;

template<typename T> class FenwickTree {
  int N, M;
  vector<T> B;
public:
  FenwickTree(int n) : N(n + 1), M(1), B(N, 0) {
    while (M * 2 <= N) M *= 2;
  }
  FenwickTree(const vector<T> &v) : N((int) v.size() + 1), M(1), B(N, 0) {
    for (int i = 0; i < N - 1; i++) add(i, v.at(i));
    while (M * 2 <= N) M *= 2;
  }
  void add(int i, T x) {
    i++;
    while (i < N) B.at(i) += x, i += i & -i;
  }
  void add(int l, int r, T x) {
    add(l, x);
    add(r + 1 , -x);
  }
  T sum(int i) {
    i++;
    T ret = 0;
    while (i > 0) ret += B.at(i), i -= i & -i;
    return ret;
  }
  T sum(int l, int r) {
    return sum(r) - sum(l - 1);
  }
  T at(int i) {
    return sum(i) - sum(i - 1);
  }
  int lower_bound(T w) {
    if (w <= 0) return 0;
    int x = 0;
    for (int k = M; k > 0; k /= 2) {
      if (x + k <= N - 1 && B.at(x + k) < w) {
        w -= B.at(x + k);
        x += k;
      }
    }
    return x;
  }
  int upper_bound(T w) {
    if (w < 0) return 0;
    int x = 0;
    for (int k = M; k > 0; k /= 2) {
      if (x + k <= N - 1 && B.at(x + k) <= w) {
        w -= B.at(x + k);
        x += k;
      }
    }
    return x;
  }
};

signed main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  int N, K;
  cin >> N >> K;
  FenwickTree<mint> FT(N * 3);
  FT.add(1, 1, 1);
  vector<pair<int, int>> V(K);
  for (int i = 0; i < K; i++) {
    int l, r;
    cin >> l >> r;
    V.at(i) = {l, r};
  }

  for (int i = 1; i < N; i++) {
    if (FT.sum(i)) {
      for (auto [l, r] : V) {
        FT.add(i + l, i + r, FT.sum(i));
      }
    }
  }
  cout << FT.sum(N) << "\n";
}


Measured memory_bytes: 5532