#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ss = stringstream;
const ll mod = 1000000000 + 7;
const ll llmax = pow(10, 18);
vector<int> Eratosthenes(ll N) {
  vector<bool> is_prime(N + 1);
  for (int i = 0; i <= N; i++) {
    is_prime[i] = true;
  }
  vector<int> P;
  for (int i = 2; i <= N; i++) {
    if (is_prime[i]) {
      for (int j = 2 * i; j <= N; j += i) {
        is_prime[j] = false;
      }
      P.emplace_back(i);
    }
  }
  return P;
}
int main() {
  ll N;
  cin >> N;
  ll K;
  cin >> K;
  vector<ll> L(K);
  vector<ll> R(K);
  ll mll = 998244353;
  vector<ll> DP(N, 0);
  vector<ll> A(N + 1);
  A[0] = 0;
  A[1] = 1;
  DP[0] = 1;
  for (ll i = 0; i < K; i++) {
    cin >> L[i];
    cin >> R[i];
  }
  for (ll i = 1; i < N; i++) {
    for (ll j = 0; j < K; j++) {
      if (i - L[j] < 0) continue;
      DP[i] += A[i - L[j] + 1] - A[i - R[j]] + mll;
      DP[i] %= mll;
    }
    A[i + 1] = (A[i] + DP[i]) % mll;
  }
  ll ans = DP[N - 1];
  cout << ans << endl;
}
