#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const long long INF = 1LL << 60;
const int INT_INF = 1 << 29;
const int MAX = 200010;
const int MOD = 998244353;
void solve() {
  int N, K;
  int dp[MAX];
  int L[12], R[12];
  vector<int> steps;
  memset(dp, 0, sizeof(dp));
  dp[1] = 1;
  cin >> N >> K;
  for (int i = 0; i < K; i++) {
    cin >> L[i] >> R[i];
  }
  for (int i = 0; i < K; i++) {
    for (int j = L[i]; j <= R[i]; j++) steps.push_back(j);
  }
  for (int i = 2; i <= N; i++) {
    long long counter = 0;
    for (int j : steps) {
      if (i - j > 0) counter += (dp[i - j] % MOD);
    }
    dp[i] = counter % MOD;
  }
  cout << dp[N] << endl;
  return;
}
int main() {
  solve();
  return 0;
}
