#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
int main(void) {
  int N, K;
  cin >> N >> K;
  vector<pii> lr(K);
  for (int i = 0; i < K; i++) {
    cin >> lr[i].first >> lr[i].second;
  }
  vector<ll> dp(N + 1, 0);
  dp[0] = 0;
  dp[1] = 1;
  for (int i = 1; i <= N; i++) {
    for (int j = 0; j < K; j++) {
      for (int d = lr[j].first; d <= min(N - i, lr[j].second); d++) {
        dp[i + d] += dp[i];
        dp[i + d] %= 998244353;
      }
    }
  }
  cout << dp[N] << endl;
  return 0;
}
