#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 998244353;
int main() {
  ll n, k;
  cin >> n >> k;
  vector<int> left(k), right(k);
  for (int i = 0; i < k; ++i) cin >> left[i] >> right[i];
  vector<ll> dp(n + 1);
  vector<ll> dpSum(n + 1);
  dp[1] = 1;
  dpSum[1] = 1;
  for (int i = 2; i <= n; ++i) {
    for (int j = 0; j < k; ++j) {
      int l = i - right[j], r = i - left[j];
      if (r < 1) continue;
      l = max(l, 1);
      ll sum = (dpSum[r] - dpSum[l - 1]) % MOD;
      dp[i] += sum;
      dp[i] = dp[i] % MOD;
    }
    dpSum[i] = (dpSum[i - 1] + dp[i]) % MOD;
  }
  cout << dp[n] << endl;
  return 0;
}
