#include <bits/stdc++.h>
using LL = long long;
using namespace std;
int mod = 998244353;
int main() {
  LL N, K;
  cin >> N >> K;
  vector<LL> Li(K), Ri(K);
  vector<bool> S_has(N + 1, false);
  for (int i = 0; i < K; i++) {
    cin >> Li[i] >> Ri[i];
    for (int j = Li[i]; j <= Ri[i]; j++) {
      S_has[j] = true;
    }
  }
  vector<LL> Dp(N + 1, 0);
  Dp[1] = 1;
  for (int i = 1; i < N; i++) {
    for (int j = 1; j <= N; j++) {
      if (S_has[j] == true && i + j <= N) {
        Dp[i + j] = (Dp[i + j] + Dp[i]) % mod;
      }
    }
  }
  cout << Dp[N] << endl;
  return 0;
}
