#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 998244353;
void solve(long N, long K, vector<long> L, vector<long> R) {
  vector<ll> ans(N, 0);
  ans[0] = 1;
  for (ll i = 0; i < N; ++i) {
    for (ll k = 0; k < K; ++k) {
      long l = L[k];
      long r = R[k];
      for (ll j = i + l; j < i + r + 1; ++j)
        if (j < N) ans[j] = (ans[i] + ans[j]) % MOD;
    }
  }
  cout << ans[N - 1] << endl;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long N, K;
  cin >> N >> K;
  vector<long> L(K);
  vector<long> R(K);
  for (ll i = 0; i < K; ++i) cin >> L[i] >> R[i];
  solve(N, K, move(L), move(R));
  return 0;
}
