#include <bits/stdc++.h>
int count(int n);
int a[200010] = {};
int b[200010] = {};
int n, k;
int l[11], r[11];
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 0; i < k; i++) {
    scanf("%d %d", &l[i], &r[i]);
    for (int j = l[i]; j <= r[i]; j++) {
      a[j] = 1;
    }
  }
  printf("%d", count(n - 1));
  return 0;
}
int count(int t) {
  int x = b[t];
  if (x == -1) {
    return 0;
  }
  if (x == 0) {
    x = a[t];
    for (int i = 1; i < t; i++) {
      if (a[i] == 1) {
        x += count(t - i);
        x %= 998244353;
      }
    }
    b[t] = x;
  }
  if (x == 0) {
    b[t] = -1;
  }
  return x;
}
