#include <bits/stdc++.h>
using ll = long long;
using namespace std;
const ll mod = 998244353;
int main() {
  int N, K;
  cin >> N >> K;
  int L[K], R[K];
  for (int i = 0; i < (K); i++) cin >> L[i] >> R[i];
  vector<ll> dp(2 * N + 1);
  dp[0] = 1;
  dp[1] = -1;
  for (int i = 0; i < (N); i++) {
    for (int j = 0; j < (K); j++) {
      dp[i + L[j]] += dp[i];
      dp[i + R[j] + 1] -= dp[i];
    }
    dp[i + 1] += dp[i];
    dp[i + 1] = (dp[i + 1] + mod) % mod;
  }
  cout << dp[N - 1] << endl;
  return 0;
}
