#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
const int INF = 1e9;
int main() {
  int n, k;
  const int max_n = 2 * 1e5;
  cin >> n >> k;
  int l[11], r[11];
  for (int i = 0; i < k; i++) cin >> l[i] >> r[i];
  vector<int> dp(max_n + 1, 0);
  vector<int> dpsum(max_n + 1, 0);
  dp[1] = 1;
  dpsum[1] = dp[1];
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < k; j++) {
      if (i - l[j] < 1)
        dp[i] += 0;
      else if (i - r[j] < 2)
        dp[i] += dpsum[i - l[j]];
      else
        dp[i] += dpsum[i - l[j]] - dpsum[i - r[j] - 1];
    }
    dp[i] %= MOD;
    if (dp[i] < 0) dp[i] += MOD;
    dpsum[i] = dpsum[i - 1] + dp[i];
    dpsum[i] %= MOD;
    if (dpsum[i] < 0) dpsum[i] += MOD;
  }
  cout << dp[n] << endl;
  return 0;
}
