#include <bits/stdc++.h>
using namespace std;
map<pair<int, int>, int> dp;
long long fact(long long n) {
  long long ans = 1;
  for (int i = 1; i <= n; i++) {
    ans *= i;
    ans = ans % 998244353;
  }
  return ans;
}
long long int findcount(int n, vector<long long int> &steps, int i, int count) {
  if (n == 0) {
    return fact(count);
  }
  if (i >= steps.size()) return 0;
  if (n < 0) return 0;
  if (dp.count({i, n}) != 0) return 0;
  long long int op1 = findcount(n - steps[i], steps, i + 1, count + 1);
  long long int op2 = findcount(n, steps, i + 1, count);
  return dp[{i, n}] = (op1 + op2) % 998244353;
}
int main() {
  long long int k, n;
  cin >> n >> k;
  vector<long long> steps;
  for (int i = 0; i < k; i++) {
    long long int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++) {
      steps.push_back(j);
    }
  }
  dp.clear();
  long long int ans = findcount(n, steps, 0, 0);
  printf("%lld\n", ans);
  return 0;
}
