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