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