#include <bits/stdc++.h>
using namespace std;
void SieveOfEratosthenes() {
  bool prime[10000001];
  memset(prime, true, sizeof(prime));
  for (long long int p = 2; p * p <= 10000000; p++) {
    if (prime[p] == true) {
      for (long long int i = p * p; i <= 10000000; i += p) {
        prime[i] = false;
      }
    }
  }
}
long long int binpow(long long int a, long long int b) {
  long long int res = 1;
  while (b > 0) {
    if (b & 1) res = (res * a);
    a = (a * a);
    b >>= 1;
  }
  return res;
}
long long int gcd(long long int a, long long int b) {
  if (b % a == 0) return a;
  return gcd(b % a, a);
}
long long int power(long long int x, long long int y, long long int p) {
  long long int r = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) r = (r * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return r;
}
long long int modInverse(long long int n, long long int p) {
  return power(n, p - 2, p);
}
long long int nCrModP(long long int n, long long int r, long long int p) {
  long long int fac[100005];
  if (r == 0) return 1;
  return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) %
         p;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long int j, i, n, t, l, r, c, h, k, m, maxi, d, x;
  cin >> n >> k;
  long long int a[300005] = {0};
  vector<long long int> v;
  for (j = 0; j < k; j++) {
    cin >> l >> r;
    a[l] = 1;
    a[r + 1] = -1;
  }
  c = 0;
  long long int dp[n + 1];
  memset(dp, 0, sizeof(dp));
  dp[0] = 0;
  for (j = 1; j <= 200006; j++) {
    c = c + a[j];
    if (c > 0) {
      v.push_back(j);
      dp[j] = 1;
    }
  }
  for (i = 1; i <= n - 1; i++) {
    for (j = 0; j < v.size(); j++) {
      if (i - (v[j]) > 0)
        dp[i] += dp[i - v[j]];
      else
        break;
      dp[i] = dp[i] % 998244353;
    }
  }
  cout << dp[n - 1];
}
