#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int M = 2;
const int mod = 998244353;
ll ans = 0;
int main(void) {
  int N, K;
  cin >> N >> K;
  vector<int> l(N + 10, 0);
  vector<int> r(N + 10, 0);
  vector<ll> dp(N + 10, 0);
  dp[1] = 1;
  vector<ll> dpsum(N + 10, 0);
  dpsum[1] = 1;
  for (int i = 1; i <= K; i++) cin >> l[i] >> r[i];
  for (int i = 2; i <= N; i++) {
    for (int j = 1; j <= K; j++) {
      int li = i - r[j];
      if (li <= 0) li = 1;
      int ri = i - l[j];
      if (ri < 0) continue;
      dp[i] += dpsum[ri] - dpsum[li - 1];
    }
    dpsum[i] = dpsum[i - 1] + dp[i];
  }
  dp[N] %= mod;
  if (dp[N] < 0) dp[N] += mod;
  cout << dp[N] << endl;
}
