#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> dp(n + 1, 0LL);
  vector<ll> L(k), R(k);
  for (ll i = 0; i < (k); i++) {
    cin >> L[i] >> R[i];
  }
  dp[1] = 1;
  for (ll now = 2; now < (n + 1); now++) {
    dp[now] = dp[now - 1];
    for (ll i = 0; i < (k); i++) {
      ll L1 = max(0LL, now - L[i]);
      ll R1 = max(0LL, now - R[i] - 1);
      dp[now] += dp[L1] - dp[R1];
      dp[now] %= 998244353;
    }
  }
  cout << dp[n] - dp[n - 1] << endl;
  return 0;
}
