#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
bool cmp(int X, int Y) { return X > Y; }
const double EPS = (1e-7);
int dcp(double A, double B) { return fabs(A - B) <= EPS ? 0 : A < B ? -1 : 1; }
long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }
long long modpow(long long a, long long b, long long m = MOD) {
  a %= m;
  long long res = 1;
  while (b) {
    if (b & 1) res = (res * a) % m;
    a = (a * a) % m;
    b >>= 1;
  }
  return res;
}
long long bpow(long long a, long long b) {
  if (b < 0) {
    return 0;
  }
  long long res = 1;
  while (b) {
    if (b & 1) res = res * a;
    a = a * a;
    b >>= 1;
  }
  return res;
}
long long modinv(long long a, long long m = MOD) { return modpow(a, m - 2, m); }
const int N = 200005;
vector<long long> adj[N];
long long vis[N];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, k;
  cin >> n >> k;
  for (long long i = 0; i < k; i++) {
    long long x, y;
    cin >> x >> y;
    vis[x]++;
    vis[y + 1]--;
  }
  for (long long i = 1; i <= N - 1; i++) {
    vis[i] += vis[i - 1];
  }
  vector<long long> a;
  for (long long i = 0; i < N; i++) {
    if (vis[i]) {
      a.push_back(i);
    }
  }
  long long dp[n + 1];
  memset(dp, 0, sizeof(dp));
  dp[1] = 1;
  for (long long i = 2; i <= n; i++) {
    for (long long j = 0; j < (int)a.size(); j++) {
      if (i - a[j] >= 0) {
        (dp[i] += dp[i - a[j]]);
        dp[i] %= MOD;
        dp[i] = (dp[i] + MOD) % MOD;
      }
    }
  }
  dp[n] = (dp[n] + MOD) % MOD;
  cout << dp[n] << '\n';
}
