#include <bits/stdc++.h>
using namespace std;
const long long int INF = 998244353;
int main(void) {
  long long N, K;
  cin >> N >> K;
  vector<pair<long long, long long>> s(K);
  for (long long i = 0; i < K; i++) {
    long long L, R;
    cin >> L >> R;
    s[i] = make_pair(L, R);
  }
  vector<long long> dp(N + 1, 0), dpsum(N + 1, 0);
  dp[1] = 1;
  dpsum[1] = 1;
  for (long long i = 2; i <= N; i++) {
    for (int j = 0; j < K; j++) {
      int li = i - s[j].second;
      int ri = i - s[j].first;
      if (ri < 0) continue;
      li = std::max(li, 1);
      dp[i] += dpsum[ri] - dpsum[li - 1];
      dp[i] %= INF;
    }
    dpsum[i] = dpsum[i - 1] + dp[i];
    dpsum[i] %= INF;
    fprintf(stderr, "dp[%d] : %d\n", i, dp[i]);
  }
  cout << dp[N] << endl;
}
