#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
static const ll mod = 998244353;
ll N, K;
ll dp[100005];
ll sum[100005];
int main() {
  cin >> N >> K;
  vector<P> A(K);
  for (ll i = 0; i < K; i++) {
    ll l, r;
    cin >> l >> r;
    P p(l, r);
    A[i] = p;
  }
  dp[0] = 1;
  sum[0] = 1;
  for (ll i = 1; i < N; i++) {
    for (ll j = 0; j < K; j++) {
      ll l = A[j].first;
      ll r = A[j].second;
      if (i - l < 0) {
      } else if (0 <= i - l && 0 <= i - r - 1) {
        dp[i] = (dp[i] + sum[i - l] - sum[i - r - 1] + 2 * mod) % mod;
      } else
        dp[i] = (dp[i] + sum[i - l]) % mod;
    }
    sum[i] = (sum[i - 1] + dp[i]) % mod;
  }
  cout << dp[N - 1] << endl;
  return 0;
}
