#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
int main() {
  cin.tie(0)->sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  vector<int> l(k), r(k);
  for (int i = 0; i < (k); i++) cin >> l[i] >> r[i];
  vector<int> dp(n + 1, 0);
  dp[0] = 1;
  dp[1] = -1;
  for (int i = 0; i < (n); i++) {
    dp[i] = ((dp[i] % MOD) + MOD) % MOD;
    dp[i + 1] = (dp[i + 1] + dp[i]) % MOD;
    for (int j = 0; j < (k); j++) {
      if (i + l[j] < n) dp[i + l[j]] += dp[i];
      if (i + r[j] + 1 < n) dp[i + r[j] + 1] -= dp[i];
    }
  }
  cout << dp[n - 1] << '\n';
  return 0;
}
