#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
int main() {
  const long long mod = 998244353;
  int N, K;
  cin >> N >> K;
  vector<int> L(K);
  vector<int> R(K);
  for (int i = 0; i < K; i++) {
    cin >> L[i] >> R[i];
  }
  sort(L.begin(), L.end());
  sort(R.begin(), R.end());
  vector<long long> dp(N + 1);
  dp[1] = 1;
  int min = L[0];
  for (int i = 1; i <= N - L[0]; i++) {
    bool frg = false;
    for (int j = 0; j < K; j++) {
      for (int k = L[j]; k <= R[j]; k++) {
        if ((i + k) <= N) {
          dp[i + k] = dp[i + k] + dp[i];
          if (dp[i + k] > mod) {
            dp[i + k] = dp[i + k] % mod;
          }
        } else {
          frg = true;
          break;
        }
      }
      if (frg) {
        break;
      }
    }
  }
  if (dp[N] >= mod) {
    dp[N] = dp[N] % mod;
  }
  cout << dp[N] << endl;
}
