#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
using ll = long long;
int main() {
  int N, K;
  cin >> N >> K;
  set<int> S;
  vector<int> L(K), R(K);
  for (int i = 0; i < K; ++i) {
    cin >> L[i] >> R[i];
    for (int d = L[i]; d <= R[i]; ++d) S.insert(d);
  }
  vector<ll> dp(N);
  dp[N - 1] = 1;
  for (int i = N - 1; i >= 0; --i) {
    for (int d : S) {
      if (i + d < N) dp[i] = (dp[i] + dp[i + d]) % MOD;
    }
  }
  cout << dp[0] << endl;
}
