#include <bits/stdc++.h>
using namespace std;
vector<int> moveDistances;
int moveCountCache[200001];
int memoizeMoveCount(int n) {
  if (n < 1)
    return 0;
  else if (n == 1)
    return 1;
  int &moveCount = moveCountCache[n];
  if (moveCount != -1) return moveCount;
  moveCount = 0;
  for (int moveDistance : moveDistances) {
    moveCount = (moveCount + memoizeMoveCount(n - moveDistance)) % 998244353;
  }
  return moveCount;
}
int main() {
  int n;
  int k;
  memset(moveCountCache, -1, sizeof(moveCountCache));
  cin >> n >> k;
  for (int i = 0; i < k; i++) {
    int leftEnd;
    int rightEnd;
    cin >> leftEnd >> rightEnd;
    for (int j = leftEnd; j <= rightEnd; j++) {
      moveDistances.push_back(j);
    }
  }
  cout << memoizeMoveCount(n) << endl;
  return 0;
}
