#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 998244353;
ll dp[200100];
bool S[200100] = {false};
int l, r;
int main() {
  int N, K;
  cin >> N >> K;
  for (int i = 0; i < K; ++i) {
    cin >> l >> r;
    for (int j = l; j <= r; ++j) S[j] = true;
  }
  for (int i = 0; i < 200100; ++i) dp[i] = 0;
  dp[1] = 1;
  for (int i = 1; i <= N; ++i) {
    if (dp[i] == 0) continue;
    for (int j = 1; j <= N; ++j) {
      if (!S[j] || i + j > N) continue;
      dp[i + j] = (dp[i + j] + dp[i]) % MOD;
    }
  }
  cout << dp[N] << endl;
  return 0;
}
