#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 998244353;
const ll INF = 1ll << 60;
int dx[4]{0, 1, 0, -1};
int dy[4]{1, 0, -1, 0};
ll dp[100000 * 2 + 10]{};
int main(int argc, char **argv) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N, K;
  cin >> N >> K;
  dp[1] = 1;
  vector<ll> L(N), R(N);
  for (ll i = (0); i < (ll)(K); ++i) cin >> L[i] >> R[i];
  vector<ll> S;
  for (ll i = (0); i < (ll)(K); ++i) {
    for (ll d = L[i]; d <= R[i]; ++d) S.push_back(d);
  }
  for (ll i = 1; i < N; ++i) {
    for (auto s : S)
      if (i + s <= N) (dp[i + s] += dp[i]) %= MOD;
  }
  std::cout << dp[N] << std::endl;
  return 0;
}
