#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> dp(n + 1, 0);
  vector<ll> L(k), R(k);
  for (ll i = 0; i < (k); i++) {
    cin >> L[i] >> R[i];
  }
  dp[1] = 1;
  for (ll now = 1; now < (n + 1); now++) {
    if (dp[now] == 0) continue;
    for (ll i = 0; i < (k); i++) {
      for (ll j = L[i]; j < (R[i] + 1); j++) {
        if (now + j > n) break;
        dp[now + j] += dp[now];
        dp[now + j] %= 998244353;
      }
    }
  }
  cout << dp[n] << endl;
  return 0;
}
