#include <bits/stdc++.h>
using namespace std;
int MOD = 998244353;
int main() {
  int N, K;
  cin >> N >> K;
  vector<int> L(K);
  vector<int> R(K);
  for (int i = 0; i < K; i++) cin >> L[i] >> R[i];
  sort(L.begin(), L.end());
  sort(R.begin(), R.end());
  queue<int> que;
  for (int i = 0; i < K; i++) {
    for (int j = L[i]; j <= R[i]; j++) que.push(j);
  }
  int s = que.size();
  vector<int> S(s);
  for (int i = 0; i < s; i++) {
    S[i] = que.front();
    que.pop();
  }
  vector<int> dp(N + 1, 0);
  dp[1] = 1;
  for (int i = 1; i <= N; i++) {
    for (int j = 0; j < s; j++) {
      if (N < i + S[j]) continue;
      dp[i + S[j]] += dp[i];
      dp[i + S[j]] %= MOD;
    }
  }
  cout << dp[N] << endl;
}
