#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 10;
const long long p = 998244353;
long long n, k;
long long a[N], idx = 0;
long long st[N];
long long dfs(long long step) {
  if (step == n) {
    return 1;
  }
  if (step > n) {
    return 0;
  }
  long long ret = 0;
  for (long long i = 0; i < idx; i++) {
    ret = (ret + dfs(step + a[i])) % p;
  }
  return ret % p;
}
int main() {
  cin >> n >> k;
  for (long long i = 0; i < k; i++) {
    long long x, y;
    cin >> x >> y;
    for (long long i = x; i <= y; i++) {
      a[idx++] = i;
    }
  }
  memset(st, false, sizeof st);
  cout << dfs(1) << endl;
  return 0;
}
