#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
const long long MOD = 998244353;
long long dp[200020];
int main() {
  int N, K;
  cin >> N >> K;
  int l[10], r[10];
  for (int i = 0; i < (K); ++i) cin >> l[i] >> r[i];
  dp[1] = 1;
  dp[2] = -1;
  for (int i = 1; i <= N; i++) {
    dp[i] = (dp[i] + dp[i - 1]) % MOD;
    for (int j = 0; j < (K); ++j) {
      if (i + l[j] <= N) dp[i + l[j]] = (dp[i + l[j]] + dp[i]) % MOD;
      if (i + r[j] + 1 <= N) dp[i + r[j] + 1] = dp[i + r[j] + 1] - dp[i];
      if (dp[i + r[j] + 1] < 0) dp[i + r[j] + 1] += MOD;
    }
  }
  cout << dp[N] << endl;
}
