#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
int main() {
  int N, K, L[10], R[10];
  cin >> N >> K;
  for (int i = 0; i < (K); i++) {
    cin >> L[i] >> R[i];
    R[i]++;
  }
  long long dp[200001] = {};
  dp[0] = 1;
  for (int i = (1); i < (N); i++) {
    dp[i] += dp[i - 1];
    dp[i] %= MOD;
    for (int j = 0; j < (K); j++) {
      dp[i + L[j]] += dp[i];
      dp[i + L[j]] %= MOD;
      dp[i + R[j]] -= dp[i];
    }
  }
  cout << dp[N] << endl;
  return 0;
}
