#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MODNormal = 1000000007;
constexpr ll MOD = 998244353;
const long long INF = numeric_limits<long long>::max();
template <class T>
void dumpVector(const vector<T>& vec) {}
int main() {
  ll N, K;
  cin >> N >> K;
  vector<ll> S;
  for (ll i = 0; i < (K); i++) {
    ll a, b;
    cin >> a >> b;
    for (ll i = a; i <= b; ++i) {
      S.push_back(i);
    }
  }
  vector<ll> dp(N + 1, 0);
  vector<bool> dpOk(N + 1, false);
  dp[0] = 1;
  dpOk[0] = true;
  for (ll i = 1; i <= N; ++i) {
    for (auto s : S) {
      if (i + s <= N) {
        if (dpOk[i - 1]) {
          dp[i - 1 + s] += dp[i - 1];
          dpOk[i - 1 + s] = true;
        }
      }
    }
  }
  cout << (dp[N - 1] % MOD) << "\n";
  return 0;
}
