#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const int INF = 1e9;
const lint LINF = 1e18;
const double EPS = 1e-10;
const int mod = 998244353;
struct mint {
  long long x;
  mint(long long x = 0) : x((x % mod + mod) % mod) {}
  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;
  }
};
int main() {
  lint N, K;
  cin >> N >> K;
  vector<lint> L(K), R(K);
  for (int i = (int)(0); i < (int)(K); i++) {
    cin >> L[i] >> R[i];
  }
  vector<mint> cnt(N + 3, 0);
  cnt[1] = 1;
  for (int i = 1; i < N + 1; i++) {
    for (int k = 0; k < K; k++) {
      int left = i + L[k], right = min(N + 1, i + R[k]);
      cnt[left] += cnt[i];
      cnt[right + 1] -= cnt[i];
    }
    cnt[i + 2] += cnt[i + 1];
  }
  cout << cnt[N].x << endl;
  return 0;
}
