#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
class mint {
 public:
  long long x;
  mint(long long 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 {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint& a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint& a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(long long 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) const {
    mint res(*this);
    return res /= a;
  }
  friend ostream& operator<<(ostream& os, const mint& m) {
    os << m.x;
    return os;
  }
};
vector<mint> _factionals = {0, 1};
mint factional(long long n) {
  if (_factionals.size() <= n) {
    long long i = _factionals.size();
    _factionals.resize(n + 1);
    for (; i <= n; i++) {
      _factionals[i] = _factionals[i - 1] * i;
    }
  }
  return _factionals[n];
}
unordered_map<long long, vector<mint>> _combinations;
mint combination(long long n, long long r) {
  if (n < 1 || r < 1 || n < r) return mint(0);
  if (n == r) return mint(1);
  if (n < 51000) return factional(n) / (factional(r) * factional(n - r));
  if (r > n - r) r = n - r;
  if (!_combinations.count(n)) _combinations[n] = {0, n};
  auto&& vec = _combinations[n];
  if (vec.size() <= r) {
    long long i = vec.size();
    vec.resize(r + 1);
    for (; i <= r; i++) {
      vec[i] = (vec[i - 1] * (n - i + 1)) / i;
    }
  }
  return vec[r];
}
unordered_map<long long, vector<mint>> _permutations;
mint permutation(long long n, long long r) {
  if (n < 1 || r < 1 || n < r) return mint(0);
  if (n < 51000) return factional(n) / factional(n - r);
  if (!_permutations.count(n)) _permutations[n] = {0, n};
  auto&& vec = _permutations[n];
  if (vec.size() <= r) {
    long long i = vec.size();
    vec.resize(r + 1);
    for (; i <= r; i++) {
      vec[i] = vec[i - 1] * (n - i + 1);
    }
  }
  return vec[r];
}
const int sqrtN = 2012;
struct SqrtDecomposition {
  int N, K;
  vector<mint> data;
  vector<mint> bucketAdd;
  SqrtDecomposition(int n) : N(n) {
    K = (N + sqrtN - 1) / sqrtN;
    data.assign(K * sqrtN, 0);
    bucketAdd.assign(K, 0);
  }
  void add(int s, int t, mint x) {
    for (int k = 0; k < K; ++k) {
      int l = k * sqrtN, r = (k + 1) * sqrtN;
      if (r <= s || t <= l) continue;
      if (s <= l && r <= t) {
        bucketAdd[k] += x;
      } else {
        for (int i = max(s, l); i < min(t, r); ++i) {
          data[i] += x;
        }
      }
    }
  }
  mint get(int i) {
    int k = i / sqrtN;
    return data[i] + bucketAdd[k];
  }
};
int n, k;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << std::setprecision(20);
  cin >> n >> k;
  vector<int> l(k), r(k);
  SqrtDecomposition sd(n * 3 + 1);
  for (int i = 0; i < k; i++) {
    cin >> l[i] >> r[i];
  }
  sd.add(0, 1, 1);
  for (int i = 0; i < n; i++) {
    for (int _k = 0; _k < k; _k++) {
      sd.add(i + l[_k], i + r[_k] + 1, sd.get(i));
    }
  }
  cout << sd.get(n - 1);
}
