#include <bits/stdc++.h>
using namespace std;
vector<int> moveDistances;
long long moveCountCache[200001] = {0, 1};
int main() {
  int n;
  int k;
  scanf("%d%d", &n, &k);
  for (int i = 0; i < k; i++) {
    int leftEnd;
    int rightEnd;
    scanf("%d%d", &leftEnd, &rightEnd);
    for (int j = leftEnd; j <= rightEnd; j++) {
      moveDistances.push_back(j);
    }
  }
  for (int i = 2; i <= n; i++) {
    for (int moveDistance : moveDistances) {
      moveCountCache[i] =
          (moveCountCache[i] +
           (i - moveDistance > 0 ? moveCountCache[i - moveDistance] : 0)) %
          998244353;
    }
  }
  printf("%d\n", moveCountCache[n]);
  return 0;
}
