#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long MOD = 998244353;
vector<int> dx = {0, 1, 0, -1};
vector<int> dy = {1, 0, -1, 0};
const ll LINF = 2e18;
const int INF = 1e9;
ll N;
ll K;
std::vector<ll> L;
std::vector<ll> R;
vector<ll> dp;
vector<pair<ll, ll>> f(ll i) {
  vector<pair<ll, ll>> ret;
  for (int k = 0; k < K; k++) {
    ll l = L.at(k);
    ll r = R.at(k);
    if (i - l > 0) {
      pair<ll, ll> p = {i - l, max(1LL, i - r)};
      ret.push_back(p);
    }
  }
  return ret;
}
void solve() {
  dp.resize(N + 1, 0);
  dp.at(0) = 1;
  for (int i = 0; i < N; i++) {
    for (auto p : f(i + 2)) {
      ll l = p.second;
      ll r = p.first;
      for (int j = l; j <= r; j++) {
        dp.at(i + 1) += dp.at(j - 1) % MOD;
      }
    }
  }
  cout << dp.at(N - 1) % MOD << endl;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  scanf("%lld", &N);
  scanf("%lld", &K);
  L.resize(K);
  R.resize(K);
  for (int i = 0; i < K; i++) {
    scanf("%lld", &L[i]);
    scanf("%lld", &R[i]);
  }
  solve();
  return 0;
}
