#include <bits/stdc++.h>
using namespace std;
template <class T>
using V = vector<T>;
using ll = long long;
const double pi = acos(-1.0);
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
const ll mod = 998244353;
void solve() {
  ll n, k;
  cin >> n >> k;
  V<ll> l(k), r(k);
  for (ll i = 0; i < k; i++) cin >> l[i] >> r[i];
  V<ll> dp(n + 5);
  dp[1] = 1;
  for (ll i = 1; i < n; i++) {
    dp[i] += dp[i - 1];
    for (ll j = 0; j < k; j++) {
      ll lf = i + l[j], ri = i + r[j] + 1;
      if (lf > n) continue;
      if (ri > n) ri = n + 1;
      dp[lf] += dp[i] % mod;
      dp[ri] -= dp[i] % mod;
    }
  }
  cout << dp[n] % mod << "\n";
  return;
}
int main() {
  solve();
  return 0;
}
