#include <bits/stdc++.h>
using namespace std;
constexpr int64_t kMod = 998244353;
int main() {
  int64_t N, K;
  cin >> N >> K;
  set<int64_t> s;
  for (int64_t k = 0; k < K; ++k) {
    int64_t l, r;
    cin >> l >> r;
    for (int64_t i = l; i <= r; ++i) {
      s.insert(i);
    }
  }
  vector<int64_t> steps(s.begin(), s.end());
  vector<int64_t> dp(N + 1);
  dp[1] = 1;
  for (int64_t n = 1; n <= N; ++n) {
    for (int64_t step : steps) {
      if (n + step <= N) {
        dp[n + step] += dp[n];
        dp[n + step] %= kMod;
      }
    }
  }
  cout << dp[N] << endl;
  return 0;
}
