#include <bits/stdc++.h>
using namespace std;
template <long long Mod>
class mod_int {
 public:
  long long x;
  mod_int(long long x = 0LL) : x((x % Mod + Mod) % Mod){};
  mod_int operator-() const { return mod_int(-x); }
  mod_int pow(long long t) const {
    if (!t) return 1;
    mod_int<Mod> a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }
  mod_int inv() const { return pow(Mod - 2); }
  mod_int operator+(const mod_int<Mod> a) const {
    return mod_int<Mod>(*this) += a;
  }
  mod_int operator-(const mod_int<Mod> a) const {
    return mod_int<Mod>(*this) -= a;
  }
  mod_int operator*(const mod_int<Mod> a) const {
    return mod_int<Mod>(*this) *= a;
  }
  mod_int operator/(const mod_int<Mod> a) const {
    return mod_int<Mod>(*this) /= a;
  }
  mod_int& operator+=(const mod_int<Mod> a) {
    (x += a.x) %= Mod;
    return *this;
  }
  mod_int& operator-=(const mod_int<Mod> a) {
    if ((x += Mod - a.x) >= Mod) x -= Mod;
    return *this;
  }
  mod_int& operator*=(const mod_int<Mod> a) {
    (x *= a.x) %= Mod;
    return *this;
  }
  mod_int& operator/=(const mod_int<Mod> a) { return *this *= a.inv(); }
  friend istream& operator>>(istream& is, mod_int<Mod>& a) { return is >> a.x; }
  friend ostream& operator<<(ostream& os, const mod_int<Mod>& a) {
    return os << a.x;
  }
};
long long N, K;
int main() {
  cin >> N >> K;
  long long dp[N + 1];
  for (int i = 0; i <= N; i++) dp[i] = 0LL;
  dp[1] = 1LL;
  dp[2] = -1LL;
  int LR[K][2];
  for (int i = 0; i < K; i++) {
    cin >> LR[i][0] >> LR[i][1];
    LR[i][1]++;
  }
  long long acc = 1LL;
  for (int i = 1; i <= N; i++) {
    if (acc == 0LL) continue;
    for (int j = 0; j < K; j++) {
      if (i + LR[j][0] <= N) dp[i + LR[j][0]] += acc;
      if (i + LR[j][1] <= N) dp[i + LR[j][1]] -= acc;
    }
    acc += dp[i + 1];
  }
  mod_int<998244353> ans = 0LL;
  for (int i = 0; i <= N; i++) ans += dp[i];
  cout << ans << endl;
  return 0;
}
