#include <bits/stdc++.h>
using namespace std;
long long dp[200005];
long long solve(long long i, long long n, set<long long> &moves) {
  if (i > n) {
    return 0;
  }
  if (i == n) {
    return 1;
  }
  if (dp[i] != -1) {
    return dp[i];
  }
  long long res = 0;
  for (long long x : moves) {
    res += (solve(i + x, n, moves));
    res %= 998244353;
  }
  dp[i] = res;
  return res;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  long long k;
  cin >> k;
  memset(dp, -1, sizeof dp);
  long long diff[n + 5];
  memset(diff, 0, sizeof diff);
  for (long long i = 0; i < k; i++) {
    long long x;
    cin >> x;
    long long y;
    cin >> y;
    diff[x]++;
    diff[y + 1]--;
  }
  for (long long i = 1; i < n + 2; i++) {
    diff[i] += diff[i - 1];
  }
  set<long long> moves;
  for (long long i = 1; i <= n; i++) {
    if (diff[i] > 0) moves.insert(i);
  }
  cout << solve(1, n, moves) << '\n';
  return 0;
}
