#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
int main() {
  int N, K;
  cin >> N >> K;
  vector<int> S(N + 1, 0);
  int L, R;
  for (int i = 0; i < K; ++i) {
    cin >> L >> R;
    for (int j = L; j <= R; ++j) {
      S[j] = 1;
    }
  }
  vector<long long> dp(N + 1, 0);
  dp[N] = 1;
  for (int i = N - 1; i >= 1; --i) {
    int maxJ = N - i;
    for (int j = 1; j <= maxJ; ++j) {
      if (S[j] == 1) {
        dp[i] += dp[i + j];
        dp[i] %= MOD;
      }
    }
  }
  cout << dp[1] << endl;
  return 0;
}
