#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 998244353;
const int INF = 1001001001;
int main() {
  ll n, k;
  cin >> n >> k;
  vector<pair<ll, ll>> pr(k);
  for (int i = 0; i < int(k); ++i) {
    ll a, b;
    cin >> a >> b;
    pr[i].first = a;
    pr[i].second = b;
  }
  sort(pr.begin(), pr.end());
  vector<ll> dp(n);
  vector<ll> dp_sum(n + 1);
  dp[0] = 1;
  dp_sum[0] = 0;
  dp_sum[1] = 1;
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < int(k); ++j) {
      ll cur_l = pr[j].first;
      ll cur_r = pr[j].second;
      if (i - cur_l < 0) break;
      if (i - cur_r >= 0) {
        dp[i] += dp_sum[i - cur_l + 1] - dp_sum[i - cur_r];
        dp[i] %= MOD;
      } else {
        for (int k = cur_l; k <= cur_r; k++) {
          if (i - k >= 0) {
            dp[i] += dp[i - k];
            dp[i] %= MOD;
          } else
            break;
        }
      }
    }
    dp_sum[i + 1] = dp[i] + dp_sum[i];
    dp_sum[i + 1] %= MOD;
  }
  if (dp[n - 1] < 0) dp[n - 1] += MOD;
  cout << dp[n - 1] << endl;
  return 0;
}
