#include <bits/stdc++.h>
namespace {
static std::array<long long, 200001> answers = {};
}
namespace ABC179 {
class D {
 public:
  D() = default;
  ~D() = default;
  static constexpr long long DIV = 998244353;
  void Run() {
    int N, K;
    std::cin >> N;
    std::cin >> K;
    std::vector<int> S = {};
    S.reserve(N);
    for (int i = 0; i < K; ++i) {
      int L, R;
      std::cin >> L;
      std::cin >> R;
      for (int j = L; j <= R; ++j) {
        S.push_back(j);
      }
    }
    std::sort(S.begin(), S.end());
    answers[N] = 1;
    for (int i = N; i > 1; --i) {
      for (auto n : S) {
        auto d = i - n;
        if (d >= 1) {
          answers[d] += answers[i];
          if (answers[d] >= DIV) {
            answers[d] -= DIV;
          }
        } else {
          break;
        }
      }
    }
    std::cout << answers[1] << std::endl;
  }
};
}  // namespace ABC179
int main() {
  ABC179::D prob;
  prob.Run();
  return 0;
}
