#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;
const int mod = 998244353;
long long tr[MAXN], dp[MAXN];
int n, k, L[15], R[15];
void update(int x, long long y) {
  for (; x <= n; x += (x & (-x))) tr[x] = (tr[x] + y) % mod;
}
long long find(int x) {
  if (!x) return 0;
  long long res = 0;
  for (; x; x -= (x & (-x))) res = (res + tr[x]) % mod;
  return res;
}
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= k; ++i) {
    scanf("%d %d", &L[i], &R[i]);
  }
  dp[1] = 1;
  update(1, 1);
  for (int i = 2; i <= n; ++i) {
    for (int j = 1; j <= k; ++j) {
      if (i <= L[j]) continue;
      dp[i] = (dp[i] + find(i - L[j]) - find(max(i - R[j] - 1, 0))) % mod;
      dp[i] = (dp[i] + mod) % mod;
    }
    update(i, dp[i]);
  }
  printf("%lld", dp[n]);
  return 0;
}
