#include <bits/stdc++.h>
int main() {
  int64_t N, K;
  std::cin >> N >> K;
  std::vector<std::pair<int64_t, int64_t>> LR;
  for (size_t k = 0; k < K; ++k) {
    int64_t L, R;
    std::cin >> L >> R;
    LR.emplace_back(L, R);
  }
  std::vector<int64_t> V;
  V.resize(2 * 100000, 0);
  V[0] = 1;
  int64_t LRC[10];
  for (size_t i = 0; i < 10; ++i) {
    LRC[i] = 0;
  }
  for (int64_t i = 1; i < N; ++i) {
    for (int64_t j = 0; j < LR.size(); ++j) {
      if (i - LR[j].second - 1 >= 0) {
        LRC[j] -= V[i - LR[j].second - 1];
      }
      if (i - LR[j].first >= 0) {
        LRC[j] += V[i - LR[j].first];
      }
    }
    for (int64_t j = 0; j < LR.size(); ++j) {
      V[i] += LRC[j];
    }
  }
  std::cout << (V[N - 1] % 998244353) << std::endl;
  return 0;
}
