#include <bits/stdc++.h>
using namespace std;
using namespace std;
long long count(int n, int memo[], int k, int l[], int r[]) {
  if (n <= 0) {
    return 0;
  }
  if (n == 1) {
    return 1;
  }
  if (memo[n] > -1) {
    return memo[n];
  }
  int ans = 0;
  for (long long i = 0; i < (long long)(k); i++) {
    if (l[i] > n) {
      continue;
    }
    for (int j = l[i]; j <= r[i]; j++) {
      ans += count(n - j, memo, k, l, r);
      ans = ans % 998244353;
    }
  }
  memo[n] = ans;
  return ans;
}
int main(void) {
  int n, k;
  cin >> n >> k;
  int l[k], r[k];
  for (long long i = 0; i < (long long)(k); i++) {
    cin >> l[i] >> r[i];
  }
  int memo[n + 1];
  for (long long i = 0; i < (long long)(n + 1); i++) {
    memo[i] = -1;
  }
  long long ans = count(n, memo, k, l, r);
  cout << ans << endl;
  return 0;
}
