#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using VP = vector<P>;
using VVP = vector<VP>;
using VS = vector<string>;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<ll>;
using VVLL = vector<VLL>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VD = vector<double>;
using VVD = vector<VD>;
static const double EPS = 1e-10;
static const double PI = acos(-1.0);
static const ll MOD = 998244353;
static const int INF = 1 << 30;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(10);
  int N, K;
  cin >> N >> K;
  VLL dp(N + 1, 0);
  dp[1] = 1;
  VI L(K), R(K);
  for (int i = (0); i < (K); ++i) cin >> L[i] >> R[i];
  VLL S(N + 1, 0);
  S[1] = 1;
  for (int i = (2); i < (N + 1); ++i) {
    for (int j = (0); j < (K); ++j) {
      int l = L[j], r = R[j];
      if (i - l < 1) break;
      dp[i] += S[i - l] - S[max(0, i - r - 1)];
    }
    dp[i] %= MOD;
    S[i] = (S[i - 1] + dp[i]) % MOD;
  }
  ll ans = dp[N];
  cout << ans << '\n';
  return 0;
}
