#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const int INF = 1001001001;
const long long mod = 998244353;
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> sum(N + 1);
  dp[1] = 1;
  sum[1] = 1;
  for (int i = 2; i <= N; i++) {
    for (int k = 0; k < K; k++) {
      int li = i - R[k];
      int ri = i - L[k];
      li = max(li, 1);
      if (ri < 0) {
        continue;
      }
      (dp[i] += (sum[ri] - sum[li - 1]) % mod) %= mod;
    }
    sum[i] = (sum[i - 1] + dp[i]) % mod;
  }
  cout << dp[N] << endl;
  return 0;
}
