#include <bits/stdc++.h>
using namespace std;
int64_t gcd(int64_t a, int64_t b) { return (a % b == 0 ? b : gcd(b, a % b)); }
int64_t lcm(int a, int b) { return (int64_t)a * b / gcd(a, b); }
int factorial(int a) {
  int b = 1;
  while (a) {
    b *= a--;
  }
  return b;
}
bool is_prime(int a) {
  if (a <= 1) return false;
  for (int i = 2; (int64_t)i * i <= a; i++) {
    if (a % i == 0) return false;
  }
  return true;
}
int get_adp(double x, int n) {
  return (int)round((x - (int)x) * pow(10, n)) % 10;
}
int64_t sigma(int64_t s, int64_t n) { return n * (2 * s + n - 1) / 2; }
int main() {
  int64_t n, k, l, r, n_vec = 0, q = 998244353;
  cin >> n >> k;
  vector<int64_t> ans(n, 0);
  vector<int64_t> vec;
  for (int i = 0; i < k; i++) {
    cin >> l >> r;
    n_vec += r - l + 1;
    for (int j = l; j <= r; j++) vec.push_back(j);
  }
  sort(vec.begin(), vec.end());
  ans[0] = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n_vec; j++) {
      if (i + vec[j] >= n) break;
      ans[i + vec[j]] += ans[i];
      ans[i + vec[j]] %= q;
    }
  }
  cout << ans[n - 1] << endl;
}
