#include <bits/stdc++.h>
static int N, K;
std::vector<std::pair<int, int> > LR;
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) {
    const int b = LR[i].first;
    const int e = LR[i].second;
    for (int d = b; d <= e; ++d) {
      if (pos + d > N) {
        break;
      }
      count += search(pos + d) % 998244353;
    }
  }
  memo[pos] = count % 998244353;
  return memo[pos];
}
int main() {
  std::cin >> N >> K;
  LR.resize(K);
  memo.resize(N, -1);
  for (int i = 0; i < K; ++i) {
    std::cin >> LR[i].first >> LR[i].second;
  }
  std::sort(LR.begin(), LR.end(),
            [](const std::pair<int, int>& r1, const std::pair<int, int>& r2) {
              return r1.second < r2.first;
            });
  std::cout << search(1) << std::endl;
  return 0;
}
