#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
const long long NUM = 10e8 + 7;
int main() {
  long long N, K;
  cin >> N >> K;
  long long L[K], R[K];
  for (long long i = 0; i < K; i++) {
    cin >> L[i] >> R[i];
  }
  vector<long long> dp(N + 1, 0);
  dp[1] = 1;
  for (long long i = 1; i < N; i++) {
    for (long long j = 0; j < K; j++) {
      for (long long m = L[j]; m <= R[j]; m++) {
        if (i + m <= N) {
          dp[i + m] = dp[i + m] + dp[i];
          dp[i + m] = dp[i + m] % 998244353;
        }
      }
    }
  }
  cout << dp[N] << endl;
}
