#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
bool xor_logic(bool x, bool y) { return (x && y) || (!x && !y); }
ll solve(ll N, ll K, vector<ll>& L, vector<ll>& R) {
  vector<ll> num_list;
  for (size_t i = 0; i < K; i++) {
    for (size_t j = L[i]; j <= R[i]; j++) {
      num_list.push_back(j);
    }
  }
  sort(((num_list).begin()), ((num_list).end()));
  vector<ll> pattern_count(N, 0);
  pattern_count[0] = 1;
  for (ll i = 1; i <= N - 1; i++) {
    for (auto&& x : num_list) {
      if (x > i) {
        break;
      }
      pattern_count[i] += pattern_count[i - x];
    }
    pattern_count[i] %= 998244353;
  }
  return pattern_count[N - 1];
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N, K;
  cin >> N >> K;
  std::vector<ll> L(K, 0), R(K, 0);
  for (size_t i = 0; i < K; i++) {
    cin >> L[i] >> R[i];
  }
  ll ans = solve(N, K, L, R);
  cout << ans << endl;
  return 0;
}
