#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vii = vector<vector<int>>;
const ll LINF = 1LL << 60;
const int INF = 1 << 29;
const ll MOD = 998244353;
template <typename T>
bool chmax(T &a, const T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T &a, const T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  int N, K;
  cin >> N >> K;
  vi L(K), R(K);
  for (int i = 0; i < K; i++) {
    cin >> L[i] >> R[i];
  }
  vector<ll> dp(N + 1, 0);
  for (int i = 0; i < K; i++) {
    dp[L[i]] = 1;
    dp[R[i]] = 1;
  }
  for (int i = 2; i <= N; i++) {
    dp[i] = dp[i - 1];
    for (int j = 0; j < K; j++) {
      if (i - R[j] >= 2) dp[i] = (dp[i] + dp[i - R[j]]) % MOD;
      if (i - L[j] - 1 >= 2) dp[i] = (dp[i] - dp[i - L[j] - 1]) % MOD;
    }
  }
  if (dp[N] < 0) dp[N] += MOD;
  cout << dp[N] << endl;
  return 0;
}
