#include <bits/stdc++.h>
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  int a[n + 1];
  int ans[n + 1];
  for (int i = 0; i < n + 1; i++) {
    a[i] = 0;
    ans[i] = 0;
  }
  for (int i = 0; i < k; i++) {
    int l, r;
    scanf("%d %d", &l, &r);
    for (int j = l; j < r + 1; j++) {
      a[j] = 1;
    }
  }
  ans[1] = 1;
  for (int i = 2; i < n + 1; i++) {
    for (int j = 1; j < i; j++) {
      ans[i] = ans[i] + ans[i - j] * a[j];
      ans[i] = ans[i] % 998244353;
    }
  }
  printf("%d\n", ans[n]);
  return 0;
}
