#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int sum = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') {
      f = -1;
    }
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    sum = (sum << 1) + (sum << 3) + (ch ^ 48);
    ch = getchar();
  }
  return sum * f;
}
int n, k, cnt = 0;
int f[2 * 100000 + 5], a[2 * 100000 + 5];
signed main() {
  n = read(), k = read();
  for (register int i = 1; i <= k; i++) {
    register int x = read(), y = read();
    for (register int j = x; j <= y; j++) {
      a[++cnt] = j;
    }
  }
  f[1] = 1;
  for (register int i = 1; i <= n; i++) {
    for (register int j = 1; j <= cnt; j++) {
      if (i - a[j] > 0) f[i] = (f[i] + f[i - a[j]]) % 998244353;
    }
  }
  printf("%d", f[n] % 998244353);
  return 0;
}
