#include <bits/stdc++.h>
static int N, K;
std::vector<int> L;
std::vector<int> R;
std::vector<int> memo;
int64_t search(int pos) {
  if (pos == N) {
    return 1;
  } else if (pos > N) {
    return 0;
  }
  if (memo[pos] >= 0) {
    return memo[pos];
  }
  int64_t count = 0;
  for (int i = 0; i < K; ++i) {
    for (int d = L[i]; d <= R[i]; ++d) {
      count += search(pos + d) % 998244353;
    }
  }
  memo[pos] = count % 998244353;
  return memo[pos];
}
int main() {
  std::cin >> N >> K;
  L.resize(K);
  R.resize(K);
  memo.resize(N, -1);
  for (int i = 0; i < K; ++i) {
    std::cin >> L[i] >> R[i];
  }
  std::cout << search(1) << std::endl;
  return 0;
}
