#include <bits/stdc++.h>
using namespace std;;
#define mod 998244353ll

int main(void){
  int N, K;
  cin >> N >> K;
  int l[K], r[K];
  for(int i = 0; i < K; i++) cin >> l[i] >> r[i];
  
  vector<long long> dp(N+1,0);
  dp[0] = 0;
  dp[1] = 1;
  
  for(int i = 1; i <= N; i++){
    for(int j = 0; j < K; j++){
      if(i - l[j] <= 0) continue;
      dp[i] = (dp[i] + dp[i-l[j]] - dp[max(0,i-r[j]-1)]) % mod;
    }
    dp[i] = (dp[i] + dp[i-1]) % mod;
  }
  
  long long ans = (dp[N] - dp[N-1] + mod) % mod;
  
  cout << ans << endl;
}