#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N;
  int K;
  cin >> N >> K;
  vector<int> L(K);
  vector<int> R(K);
  for (int i = 0; i < K; i++) {
    cin >> L[i] >> R[i];
  }
  vector<long long> dp(N + 1, 0);
  vector<long long> dpsum(N + 1, 0);
  dp[1] = 1;
  dpsum[1] = 1;
  for (int i = 2; i <= N; i++) {
    for (int j = 0; j < K; j++) {
      dp[i] += dpsum[max(i - L[j], 0)] - dpsum[max(i - R[j] - 1, 0)];
      dp[i] %= 998244353;
    }
    dpsum[i] = dpsum[i - 1] + dp[i];
    dpsum[i] %= 998244353;
  }
  cout << dp.at(N) % 998244353 << endl;
}
