#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
int n, k, sum[500005], L[200005], R[200005];
void add(int x, int c) {
  for (; x <= n; x += x & -x) sum[x] = (sum[x] + c) % mod;
}
int que(int x) {
  int ret = 0;
  for (; x >= 1; x -= x & -x) ret = (ret + sum[x]) % mod;
  return ret;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= k; i++) {
    scanf("%d%d", &L[i], &R[i]);
  }
  sum[1] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= k; j++) {
      if (i + L[j] <= n) add(i + L[j], que(i));
      add(min(n + 1, i + R[j] + 1), -que(i));
    }
  }
  printf("%d\n", que(n));
  return 0;
}
