#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  int64_t N;
  int K;
  cin >> N >> K;
  vector<int64_t> susumu_kazu;
  for (int i = 0; i < K; i++) {
    int64_t l, r;
    cin >> l >> r;
    for (int64_t j = l; j <= r; j++) {
      susumu_kazu.emplace_back(j);
    }
  }
  int64_t susumu_size = susumu_kazu.size();
  vector<int64_t> dp(N + 1, 0);
  dp[1] = 1;
  for (int64_t i = 1; i < N; i++) {
    for (int64_t j = 0; j < susumu_size; j++) {
      int64_t num = susumu_kazu[j];
      if ((i + num) > N) {
        continue;
      }
      dp[i + num] += dp[i];
      dp[i + num] %= 998244353;
    }
  }
  cout << dp[N] % 998244353 << endl;
  return 0;
}
