#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using Vi = vector<int>;
int main() {
  ll N, K;
  cin >> N >> K;
  vector<pair<ll, ll>> V;
  for (ll i = 0; i < K; i++) {
    ll L, R;
    cin >> L >> R;
    V.push_back(make_pair(L, R));
  }
  sort(V.begin(), V.end());
  vector<long long> dp(200010, 0);
  dp[1] = 1;
  dp[1 + V[0].first] = 1;
  for (ll i = V[0].first + 2; i <= 200010; i++) {
    long long dif = 0;
    for (auto v : V) {
      dif += (dp[max(0LL, i - v.first)] - dp[max(0LL, i - v.second - 1)]);
      dif %= 998244353;
    }
    dp[i] = dp[i - 1] + dif;
    dp[i] %= 998244353;
  }
  cout << dp[N] << endl;
}
