#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, K;
  cin >> N >> K;
  int LR[N][2];
  for (int i = (0); i < (K); ++i) cin >> LR[i][0] >> LR[i][1];
  long long mmm = 998244353;
  vector<long long> DP(N + 1);
  vector<long long> DPsum(N + 1);
  DP[1] = 1;
  DPsum[1] = 1;
  for (int i = 2; i <= N; i++) {
    for (int j = (0); j < (K); ++j) {
      int li = i - LR[j][1];
      int ri = i - LR[j][0];
      if (ri < 0) continue;
      li = max(li, 1);
      DP[i] = ((DP[i] + (DPsum[ri] - DPsum[li - 1]) % mmm) + mmm) % mmm;
    }
    DPsum[i] = (DPsum[i - 1] + DP[i]) % mmm;
  }
  cout << (DP[N]) << '\n';
  return 0;
}
