#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const 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];
  vector<int> dp(N + 100);
  dp[1] = 1;
  for (int i = 1; i < N + 1; i++) {
    dp[i] += dp[i - 1];
    dp[i] %= MOD;
    for (int j = 0; j < (K); ++j) {
      int l = L[j] + i;
      int r = min(R[j] + i, N + 10);
      dp[l] += dp[i];
      dp[l] %= MOD;
      dp[r + 1] += MOD;
      dp[r + 1] -= dp[i];
      dp[r + 1] %= MOD;
    }
  }
  cout << (dp[N] - dp[N - 1] + MOD) % MOD << endl;
  return 0;
}
