#include <bits/stdc++.h>
using namespace std;
const long long INF = INT_MAX / 4;
const long long MOD = 998244353;
const double EPS = 1e-14;
const bool DEBUG = false;
const string YES = "YES";
const string NO = "NO";
const string Yes = "Yes";
const string No = "No";
template <class T>
void debug(T head) {
  if (DEBUG) {
    cout << head << endl;
  }
}
template <class Head, class... Body>
void debug(Head head, Body... body) {
  if (DEBUG) {
    cout << head << " ";
    debug(body...);
  }
}
void answer() {
  long N, K;
  cin >> N >> K;
  vector<unsigned long long> L(K), R(K);
  vector<unsigned long long> dp(N, 0), csum(N, 0);
  for (int i = 0; i < K; ++i) {
    cin >> L[i] >> R[i];
  }
  dp[0] = 1;
  csum[0] = dp[0];
  for (int i = 1; i < N; ++i) {
    for (int j = 0; j < K; ++j) {
      dp[i] += csum[max(0ull, i - L[j])] - csum[max(0ull, i - R[j] - 1)] + MOD;
      dp[i] %= MOD;
    }
    dp[i] %= MOD;
    debug(dp[i]);
    csum[i] = (csum[i - 1] + dp[i]) % MOD;
  }
  cout << dp[N - 1] << endl;
  return;
}
int main(int argc, char* argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout.precision(16);
  answer();
  return 0;
}
