#include <bits/stdc++.h>
int main() {
  int n, k;
  std::cin >> n;
  std::cin >> k;
  std::vector<int> lr;
  int l, r;
  for (; std::cin >> l && std::cin >> r;) {
    for (int i = l; i <= r; ++i) {
      lr.push_back(i);
    }
  }
  std::sort(lr.begin(), lr.end());
  std::uint64_t M = 998244353;
  std::vector<std::uint64_t> tmp(n, 0);
  tmp[0] = 1;
  for (int i = 0; i < n; ++i) {
    for (auto d : lr) {
      if (i + d >= n) break;
      tmp[i + d] += tmp[i];
      tmp[i + d] %= M;
    }
  }
  std::cout << tmp[n - 1];
}
