#include <bits/stdc++.h>
using namespace std;
const int mxN = 2e5;
const int mod = 998244353;
long long countWays(vector<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 - arr[j]];
  return count[N];
}
int main() {
  long long n, k;
  cin >> n >> k;
  vector<long long> c(n + 1, 0);
  for (int i = 0; i < k; i++) {
    long long l, r;
    cin >> l >> r;
    for (int i = l; i <= r; i++) c[i]++;
  }
  vector<long long> jumps;
  for (int i = 1; i < n + 1; i++) {
    if (c[i] >= 1) jumps.push_back(i);
  }
  long long dim = jumps.size();
  long long ans = countWays(jumps, dim, n - 1) % mod;
  cout << ans;
}
