#include <bits/stdc++.h>
using namespace std;
long long MOD = 998244353;
vector<long long> DP;
vector<long long> S;
set<long long> Sets;
long long solver(long long n) {
  if (n == 1) return 1;
  if (n <= 0) return 0;
  auto itr = Sets.find(n);
  if (itr != Sets.end()) {
    return DP[n];
  }
  long long ret = 0;
  for (long long i = 0; i < S.size(); i++) {
    ret += (solver(n - S[i])) % MOD;
    ret = (ret + MOD) % MOD;
  }
  DP[n] = ret;
  Sets.insert(n);
  return ret;
}
int main(void) {
  long long N, K;
  set<long long> S_tmp;
  cin >> N >> K;
  vector<long long> tmp(N + 5, 0), s;
  DP = tmp;
  long long L, R;
  vector<long long> M(N + 5, 0);
  for (long long i = 0; i < K; i++) {
    cin >> L >> R;
    for (long long l = L; l <= R; l++) {
      s.push_back(l);
    }
  }
  S = s;
  DP[1] = 1;
  solver(N);
  cout << DP[N] << endl;
  return 0;
}
