#include <bits/stdc++.h>
using namespace std;
long long max(long long a, long long b) {
  if (a > b)
    return a;
  else
    return b;
}
long long min(long long a, long long b) {
  if (a < b)
    return a;
  else
    return b;
}
long long n, k, x, y;
set<long long> s;
long long dp[200005];
long long f(long long cur) {
  if (cur == n) return 1;
  if (dp[cur] != -1) return dp[cur];
  long long ans = 0;
  for (long long x : s) {
    if (cur + x <= n) {
      ans = (ans + f(cur + x)) % 998244353;
    } else
      break;
  }
  return dp[cur] = ans % 998244353;
}
int main() {
  cin >> n >> k;
  for (int i = 1; i <= k; i++) {
    cin >> x >> y;
    for (int j = x; j <= y; j++) s.insert(j);
  }
  memset(dp, -1, sizeof(dp));
  cout << f(1) << endl;
  return 0;
}
