#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
long long binpow(long long a, long long b) {
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = (res * a);
    a = (a * a);
    b >>= 1;
  }
  return res;
}
const int N = 1e6 + 5;
void solve() {
  int n, k;
  cin >> n >> k;
  int dp[n + 1], pref[n + 1];
  memset(dp, 0, sizeof(dp));
  memset(pref, 0, sizeof(pref));
  dp[1] = 1, pref[1] = 1;
  int l[k], r[k];
  for (int i = 0; i < k; i++) cin >> l[i] >> r[i];
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < k; j++) {
      if (i <= l[j]) continue;
      int L = l[j];
      int R = min(r[j], i - 1);
      dp[i] = (dp[i] % mod + (pref[i - L] - pref[i - R - 1]) % mod) % mod;
    }
    pref[i] = (pref[i - 1] % mod + dp[i] % mod) % mod;
  }
  cout << dp[n] << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  while (t--) solve();
  return 0;
}
