#include <bits/stdc++.h>
using namespace std;
;
int main(void) {
  int N, K;
  cin >> N >> K;
  int a[K], b[K];
  vector<bool> S(N + 1, 0);
  for (int i = 0; i < K; i++) {
    cin >> a[i] >> b[i];
    for (int j = a[i]; j < b[i] + 1; j++) S[j] = 1;
  }
  vector<long long> dp(N + 1, 0);
  dp[1] = 1;
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j < i; j++) {
      if (S[j]) {
        dp[i] = (dp[i] + dp[i - j]) % 998244353LL;
      }
    }
  }
  cout << dp[N] << endl;
}
