#include <bits/stdc++.h>

#include <atcoder/all>

#define rep(i, ss, ee) for (int i = ss; i < ee; ++i)

using namespace std;
using namespace atcoder;
using ll = long long;
using mint = static_modint<998244353>;

int N, K;
vector<mint> dpsum;
vector<mint> dp;
vector<int> l, r;

void input() {
  cin >> N >> K;
  dp.resize(N + 1);
  dpsum.resize(N + 1);
  dp[1] = 1;
  dpsum[1] = 1;
  l.resize(K);
  r.resize(K);
  rep(i, 0, K) {
    cin >> l[i];
    cin >> r[i];
  }
}

void solve() {
  rep(i, 2, N + 1) {
    rep(j, 0, K) {
      int li = i - r[j];
      int ri = i - l[j];
      if (ri < 0) continue;
      li = max(1, li);
      dp[i] += dpsum[ri] - dpsum[li - 1];
    }
    dpsum[i] = dpsum[i - 1] + dp[i];
  }
  cout << dp[N].val() << endl;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  input();
  solve();
}