#include <bits/stdc++.h>
using namespace std;
int main() {
  static long long masu[200001] = {0};
  static int S[200001] = {0};
  int N, K;
  int L, R;
  int Scount = 0;
  int ans = 0;
  cin >> N >> K;
  for (int i = 0; i < K; i++) {
    cin >> L >> R;
    for (int j = L; j <= R; j++) {
      S[Scount++] = j;
    }
  }
  for (int i = 0; i < Scount - 1; i++) {
    for (int j = Scount - 1; j >= i + 1; j--) {
      if (S[j] < S[j - 1]) {
        int temp = S[j];
        S[j] = S[j - 1];
        S[j - 1] = temp;
      }
    }
  }
  masu[0] = 1;
  for (int i = 0; i < N; i += S[0]) {
    for (int j = 0; j < Scount; j++) {
      if (i + S[j] >= N) break;
      masu[i + S[j]] += masu[i];
      masu[i + S[j]] %= 998244353;
    }
  }
  cout << masu[N - 1] << endl;
  return 0;
}
