#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 998244353;
vector<ll> dp(2 * 10e5, -1);
ll calc(ll n, vector<pair<ll, ll>> *lr) {
  if (dp[n] != -1) return dp[n];
  ll sum = 0;
  for (ll i = 0; i < (*lr).size(); i++) {
    for (ll j = (*lr)[i].first; j <= (*lr)[i].second; j++) {
      if (n - j > 0)
        sum += calc(n - j, lr) % mod;
      else if (n == j) {
        sum += 1;
        break;
      }
    }
  }
  dp[n] = sum % mod;
  return dp[n];
}
int main() {
  ll N, K;
  scanf("%lld %lld\n", &N, &K);
  ;
  vector<pair<ll, ll>> lr(K);
  for (ll i = 0; i < K; i++) {
    scanf("%lld", &(lr[i].first));
    scanf("%lld", &(lr[i].second));
  }
  ll ans = calc(N - 1, &lr);
  printf("%lld\n", ans);
}
