#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<ll> S;
vector<ll>::iterator min_s;
map<ll, ll> memo;
ll count_reach(ll i) {
  decltype(memo)::iterator it = memo.find(i);
  if (it != memo.end()) return memo[i];
  if (i == 1) {
    return 1;
  } else if (i < *min_s)
    return 0;
  ll count = 0;
  for (auto d : S) count += count_reach(i - d);
  memo[i] = count % 998244353;
  return memo[i];
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll i, j;
  ll N, K;
  cin >> N >> K;
  for (ll i = 0; i < ll(K); i++) {
    ll L, R;
    cin >> L >> R;
    vector<ll> s(size_t(R - L + 1));
    iota(s.begin(), s.end(), L);
    for (ll j = 0; j < ll(s.size()); j++) {
      S.push_back(s[j]);
    }
  }
  i = 0;
  min_s = min_element(S.begin(), S.end());
  cout << count_reach(N) << endl;
  return 0;
}
