#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <typename T1, typename T2>
bool chmax(T1 &a, T2 b) {
  if (a < b) {
    a = b;
    return true;
  } else
    return false;
}
template <typename T1, typename T2>
bool chmin(T1 &a, T2 b) {
  if (a > b) {
    a = b;
    return true;
  } else
    return false;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  vector<ll> pos(400010, 0);
  vector<ll> jump;
  ll N, K, MOD = 998244353;
  cin >> N >> K;
  for (ll i = 0; i < K; ++i) {
    ll L, R;
    cin >> L >> R;
    while (L <= R) {
      jump.push_back(L);
      L++;
    }
  }
  pos[200001] = 1;
  ll sz = jump.size();
  for (ll i = 2; i <= N; i++) {
    for (ll j = 0; j < sz; ++j) {
      (pos[200000 + i] += pos[200000 + i - jump[j]]) %= MOD;
    }
  }
  cout << pos[200000 + N] << endl;
}
