#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int MOD = 998244353;
  int N, K;
  long long Ans;
  cin >> N >> K;
  vector<int> l(K), r(K);
  for (int i = 0; i < (int)K; ++i) cin >> l[i] >> r[i];
  vector<int> dp(N + 1);
  vector<int> dpsum(N + 1);
  dp[1] = 1;
  dpsum[1] = 1;
  for (int i = 2; i <= N; i++) {
    for (int j = 0; j < (int)K; ++j) {
      int li = i - r[j];
      int ri = i - l[j];
      if (ri < 0) continue;
      li = max(li, 1);
      dp[i] += dpsum[ri] - dpsum[li - 1];
      dp[i] %= MOD;
    }
    dpsum[i] = dpsum[i - 1] + dp[i];
    dpsum[i] %= MOD;
  }
  if (dp[N] < 0) dp[N] += MOD;
  cout << dp[N] << endl;
}
long long mod(long long val, long long m = 1e9 + 7) {
  long long res = val % m;
  if (res < 0) res += m;
  return res;
}
long long pow_kai(long long a, long long n, long long m = 1e9 + 7) {
  long long x = 1;
  for (int i = 0; i < (int)n; ++i) {
    x *= a;
    x %= m;
  }
  return x;
}
