#include <bits/stdc++.h>
using namespace std;
const long long N = 1000001;
vector<long long> a;
long long power(long long x, unsigned long long y) {
  long long res = 1;
  while (y > 0) {
    if (y & 1) res = res * x;
    y = y >> 1;
    x = x * x;
  }
  return res;
}
long long maxSubArray(long long a[], long long sze) {
  long long max_so_far = 0, max_ending = 0;
  for (long long i = 0; i < sze; i++) {
    max_ending = max_ending + a[i];
    if (max_ending < 0)
      max_ending = 0;
    else if (max_so_far < max_ending)
      max_so_far = max_ending;
  }
  return max_so_far;
}
long long factorialNumInverse[N + 1];
long long naturalNumInverse[N + 1];
long long fact[N + 1];
void InverseofNumber(long long p) {
  naturalNumInverse[0] = naturalNumInverse[1] = 1;
  for (long long i = 2; i <= N; i++)
    naturalNumInverse[i] = naturalNumInverse[p % i] * (p - p / i) % p;
}
void InverseofFactorial(long long p) {
  factorialNumInverse[0] = factorialNumInverse[1] = 1;
  for (long long i = 2; i <= N; i++)
    factorialNumInverse[i] =
        (naturalNumInverse[i] * factorialNumInverse[i - 1]) % p;
}
void factorial(long long p) {
  fact[0] = 1;
  for (long long i = 1; i <= N; i++) {
    fact[i] = (fact[i - 1] * i) % p;
  }
}
long long Binomial(long long N, long long R, long long p) {
  long long ans =
      ((fact[N] * factorialNumInverse[R]) % p * factorialNumInverse[N - R]) % p;
  return ans;
}
using namespace std;
long long countWays(long long arr[], long long m, long long N) {
  long long count[N + 1];
  memset(count, 0, sizeof(count));
  count[0] = 1;
  for (long long i = 1; i <= N; i++)
    for (long long j = 0; j < m; j++)
      if (i >= arr[j]) {
        count[i] =
            (count[i] % 998244353 + count[i - arr[j]] % 998244353) % 998244353;
      }
  return count[N] % 998244353;
}
void solve() {
  long long n, k;
  cin >> n >> k;
  vector<pair<long long, long long>> v;
  for (long long i = 0; i < k; i++) {
    long long a, b;
    cin >> a >> b;
    v.push_back(make_pair(a, b));
  }
  sort(v.begin(), v.end());
  map<long long, long long> m;
  vector<long long> v1;
  for (long long i = 0; i < k; i++) {
    for (long long j = v[i].first; j <= v[i].second; j++) {
      if (m[j] == 0) {
        v1.push_back(j);
        m[j]++;
      }
    }
  }
  sort(v1.begin(), v1.end());
  long long arr[v1.size()];
  for (long long i = 0; i < v1.size(); i++) {
    arr[i] = v1[i];
  }
  long long m1 = sizeof(arr) / sizeof(arr[0]);
  long long ans = countWays(arr, m1, n - 1);
  cout << ans << "\n";
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long test;
  test = 1;
  while (test--) {
    solve();
  }
  return 0;
}
