#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, K;
  cin >> N >> K;
  vector<int> L(K), R(K);
  for (int i = 0; i < K; i++) {
    cin >> L[i] >> R[i];
  }
  vector<int> Dp(N + 1);
  vector<int> DpSum(N + 1);
  Dp[1] = 1;
  DpSum[1] = 1;
  for (int i = 2; i <= N; i++) {
    for (int j = 0; j < K; j++) {
      int left = i - R[j];
      int right = i - L[j];
      if (left < 0) left = max(left, 1);
      if (right < 0) continue;
      Dp[i] += DpSum[right] - DpSum[left - 1];
      if (Dp[i] >= 998244353) Dp[i] %= 998244353;
    }
    DpSum[i] = DpSum[i - 1] + Dp[i];
    if (DpSum[i] >= 998244353) DpSum[i] %= 998244353;
  }
  cout << Dp[N] << endl;
  return 0;
}
