#include <bits/stdc++.h>
using namespace std;
long long int dp[int(1e5 + 10)], pre[int(1e5 + 10)];
int l[int(1e5 + 10)], r[int(1e5 + 10)], n, k;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cout.precision(10);
  cin >> n >> k;
  for (int i = 1; i <= k; i++) cin >> l[i] >> r[i];
  pre[0] = dp[0] = 0ll;
  pre[1] = dp[1] = 1ll;
  for (int i = 2; i <= n; i++) {
    dp[i] = 0ll;
    for (int j = 1, u, v; j <= k; j++) {
      if (l[j] >= i) continue;
      u = l[j];
      v = min(i - 1, r[j]);
      dp[i] = ((dp[i] + pre[i - u]) % 998244353 - pre[i - v - 1]) % 998244353;
      if (dp[i] < 0ll) dp[i] += 998244353;
    }
    pre[i] = (pre[i - 1] + dp[i]) % 998244353;
  }
  cout << dp[n] << endl;
  return 0;
}
