#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
const int INF = 1000100100;
ll MOD = 998244353;
ll N, K;
vector<ll> S;
vector<ll> memo(2 * 1e5, -1);
int main() {
  cin >> N >> K;
  for (ll i = 0; i < (K); ++i) {
    ll L, R;
    cin >> L >> R;
    for (ll j = min(L, R); j <= max(L, R); ++j) {
      S.emplace_back(j);
    }
  }
  sort(S.begin(), S.end());
  ll ans = 0;
  vector<ll> cnts(N + 1, 0);
  cnts[1] = 1;
  for (ll m = 2; m <= N; ++m) {
    for (ll i = 0; i < (S.size()); ++i) {
      if (m - S[i] >= 1) {
        cnts[m] += cnts[m - S[i]];
        ans %= MOD;
      }
    }
  }
  ans = cnts[N] % MOD;
  cout << ans << endl;
  return 0;
}
