#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const int mod = 998244353;
const int INF = (int)1e9;
ll fac[510000];
ll calc(ll a, ll b, ll p) {
  if (b == 0) return 1;
  if (b % 2 == 0) {
    ll d = calc(a, b / 2, p);
    return (d * d) % p;
  } else
    return (a * calc(a, b - 1, p)) % p;
}
void COMinit(void) {
  fac[0] = fac[1] = 1;
  for (int i = 2; i <= 510000; i++) {
    fac[i] = fac[i - 1] * i;
    fac[i] %= mod;
  }
}
ll nCr(ll n, ll r) {
  ll denom = fac[r] * fac[n - r] % mod;
  return fac[n] * calc(denom, mod - 2, mod) % mod;
}
ll dp[200010];
signed main(void) {
  int n, k;
  set<int> st;
  COMinit();
  cin >> n >> k;
  for (int i = 0; i < (k); i++) {
    int l, r;
    cin >> l >> r;
    for (int i = l; i <= r; i++) st.insert(i);
  }
  for (int i = 0; i < (n); i++) dp[i] = 0;
  dp[1] = 1;
  for (int i = 1; i <= n; i++) {
    for (auto j : st) {
      if (i - j >= 0) dp[i] += dp[i - j];
      dp[i] %= mod;
    }
  }
  cout << dp[n] << endl;
  return 0;
}
