#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll mod = 998244353;
vector<ll> note;
ll N, K;
vector<ll> vec;
ll dp(ll i) {
  if (note[i - 1] >= 0) {
    return note[i - 1];
  }
  ll s = 0;
  ll j = 0;
  while (j < vec.size()) {
    if (i + vec[j] > N) {
      break;
    }
    s += dp(i + vec[j]);
    s %= mod;
    j++;
  }
  note[i - 1] = s;
  return s;
}
int main() {
  cin >> N >> K;
  note = vector<ll>(N, -1);
  note[N - 1] = 1;
  vec = vector<ll>(0);
  vector<pair<ll, ll>> A(K);
  for (ll i = 0; i < K; i++) {
    ll L, R;
    cin >> L >> R;
    A[i] = make_pair(L, R);
  }
  sort(A.begin(), A.end());
  for (ll i = 0; i < K; i++) {
    ll L, R;
    tie(L, R) = A[i];
    for (ll j = L; j <= R; j++) {
      vec.push_back(j);
    }
  }
  cout << dp(1) << endl;
}
