#include <bits/stdc++.h>
using namespace std;
vector<long long> fact;
vector<long long> ifact;
vector<long long> inv;
vector<long long> pow2;
const long long MOD = 998244353;
long long add(long long a, long long b) {
  a += b;
  while (a >= MOD) a -= MOD;
  return a;
}
void radd(long long& a, long long b) { a = add(a, b); }
long long mult(long long a, long long b) { return (a * 1LL * b) % MOD; }
void rmult(long long& a, long long b) { a = mult(a, b); }
long long modpow(long long a, long long b) {
  long long r = 1;
  while (b) {
    if (b & 1) r = mult(r, a);
    a = mult(a, a);
    b >>= 1;
  }
  return r;
}
long long choose(long long a, long long b) {
  if (a < 0 || b < 0) return 0;
  if (a < b) return 0;
  if (b == 0) return 1;
  if (a == b) return 1;
  return mult(fact[a], mult(ifact[b], ifact[a - b]));
}
long long inverse(long long a) { return modpow(a, MOD - 2); }
void init(long long _n) {
  fact.clear();
  ifact.clear();
  inv.clear();
  pow2.clear();
  fact.resize(_n + 1);
  ifact.resize(_n + 1);
  inv.resize(_n + 1);
  pow2.resize(_n + 1);
  pow2[0] = 1;
  ifact[0] = 1;
  fact[0] = 1;
  for (long long i = 1; i <= _n; i++) {
    pow2[i] = add(pow2[i - 1], pow2[i - 1]);
    fact[i] = mult(fact[i - 1], i);
  }
  ifact[_n] = inverse(fact[_n]);
  for (long long i = _n - 1; i >= 1; i--) {
    ifact[i] = mult(ifact[i + 1], i + 1);
  }
  for (long long i = 1; i <= _n; i++) {
    inv[i] = mult(fact[i - 1], ifact[i]);
  }
}
const long long N = 2e5 + 7;
long long n, k;
long long m;
vector<long long> a;
long long dp[N];
long long dfs(long long idx) {
  if (idx == n - 1) return 1;
  long long& ans = dp[idx];
  if (ans + 1) return ans;
  ans = 0;
  for (auto it : a) {
    if (idx + it < n) {
      radd(ans, dfs(idx + it));
    }
  }
  return ans;
}
void solve() {
  cin >> n >> k;
  for (long long i = 0; i < (k); i++) {
    long long x, y;
    cin >> x >> y;
    for (long long j = x; j < (y + 1); j++) a.push_back(j);
  }
  sort(a.begin(), a.end());
  a.erase(unique(a.begin(), a.end()), a.end());
  memset(dp, (long long)(-1), sizeof(dp));
  cout << dfs(0);
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t = 1;
  while (t--) {
    solve();
  }
}
