#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int n, m, step[maxn];
long long d[maxn];
int main() {
  scanf("%d%d", &n, &m);
  int cnt = 0;
  for (int i = 0, l, r; i < m; i++) {
    scanf("%d%d", &l, &r);
    for (int j = l; j <= r; j++) step[cnt++] = j;
  }
  sort(step, step + cnt);
  d[1] = 1;
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < cnt; j++) {
      if (i + step[j] > n) break;
      d[i + step[j]] = (d[i + step[j]] + d[i]) % 998244353;
    }
  }
  printf("%lld", d[n]);
  return 0;
}
