#include <bits/stdc++.h>
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using ii = pair<int, int>;
using vvi = vector<vi>;
using vii = vector<ii>;
using gt = greater<int>;
using minq = priority_queue<int, vector<int>, gt>;
using P = pair<ll, ll>;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
ll dp[200005];
ll dpsum[200005];
int mod = 998244353;
int main() {
  int N, K;
  cin >> N >> K;
  vi L(N), R(N);
  for (int i = 0; i < (K); ++i) cin >> L[i] >> R[i];
  dp[1] = 1;
  dpsum[1] = dp[1];
  for (ll i = 2; i <= N; ++i) {
    for (int j = 0; j < (K); ++j) {
      int l = i - R[j];
      int r = i - L[j];
      if (r < 0) continue;
      chmax(l, 1);
      ll ad = dpsum[r] - dpsum[l - 1];
      ad %= mod;
      (dp[i] += ad) %= mod;
      dpsum[i] = (dpsum[i - 1] + dp[i]) % mod;
    }
  }
  cout << dp[N] << endl;
  return 0;
}
