#include <bits/stdc++.h>
static int N, K;
std::vector<std::pair<int, int> > LR;
std::vector<int64_t> memo;
int main() {
  std::cin >> N >> K;
  LR.resize(K);
  memo.resize(N + 1, -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;
            });
  memo[N] = 1;
  for (int pos = N - 1; pos >= 1; --pos) {
    int64_t count = 0;
    for (int i = 0; i < K; ++i) {
      const int end = pos + LR[i].second;
      bool finish = false;
      for (int pos_move = pos + LR[i].first; pos_move <= end; ++pos_move) {
        if (pos_move > N) {
          finish = true;
          break;
        }
        count += memo[pos_move];
      }
      if (finish) {
        break;
      }
    }
    memo[pos] = count % 998244353;
  }
  std::cout << memo[1] << std::endl;
  return 0;
}
