#include <bits/stdc++.h>
using namespace std;
long long n;
long long k;
long long mod = 998244353;
vector<long long> v;
long long y;
long long dp[200005];
long long solve(long long i) {
  if (i > n) return 0;
  if (i == n) return 1;
  if (dp[i] != -1) return dp[i];
  long long ans = 0;
  for (int o = 0; o < y; o++) {
    if (i + v[o] <= n) ans += solve(i + v[o]);
  }
  dp[i] = ans % mod;
  return dp[i];
}
int main() {
  cin >> n >> k;
  for (long long i = 1; i <= n; i++) dp[i] = -1;
  for (long long i = 0; i < k; i++) {
    long long l, r;
    cin >> l >> r;
    for (long long j = l; j <= r; j++) v.push_back(j);
  }
  y = v.size();
  cout << solve(1) << endl;
  return 0;
}
