#include <bits/stdc++.h>
const long long mod = 998244353;
long long dp[202020];
std::vector<int> v;
long long dfs(int node) {
  long long res = 0;
  if (dp[node] >= 0) return dp[node];
  for (int i = 0; i < v.size(); i++) {
    if (node <= v[i] > 0) break;
    res = (res + dfs(node - v[i])) % mod;
  }
  return dp[node] = res % mod;
}
int main(void) {
  int N, K;
  scanf("%d%d", &N, &K);
  for (int i = 0; i < K; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    for (int j = x; j <= y; j++) {
      v.push_back(j);
    }
  }
  std::sort(v.begin(), v.end());
  std::fill_n(dp, 202020, -1);
  dp[1] = 1;
  dfs(N);
  printf("%lld\n", dp[N] % mod);
  return 0;
}
