#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
constexpr ll MOD = 998244353;
int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n, k;
  ll ans = 0;
  cin >> n >> k;
  vector<ll> l(k), r(k);
  vector<ll> dp(n, 0);
  for (ll i = 0; i < k; i++) {
    cin >> l[i] >> r[i];
  }
  sort(l.begin(), l.end());
  sort(r.begin(), r.end());
  dp[0] = 1;
  for (ll j = 0; j < n; j++) {
    for (ll i = 0; i < k; i++) {
      for (ll x = l[i]; x <= r[i]; x++) {
        if (j + x < n) dp[j + x] = (dp[j] + dp[j + x]) % MOD;
      }
    }
  }
  cout << dp[n - 1] << endl;
  return 0;
}
