#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll mod=998244353;
int main(void){
  ll n,k; cin>>n>>k;
  vector<int> l(k),r(k);
  for(int i=0; i<k; ++i) cin>>l[i]>>r[i];
  vector<ll> dp(n,0),sdp(n+1,0);
  dp[0]=sdp[1]=1;
  for(int i=1; i<n; ++i){
    for(int j=0; j<k; ++j){
      ll left=max(0,i-r[j]);
      ll right=max(0,i-l[j]+1);
      dp[i]=dp[i]+sdp[right]-sdp[left];
      if(dp[i]>=mod) dp[i]-=mod; else if(dp[i]<0) dp[i]+=mod;
    }
    sdp[i+1]=(sdp[i]+dp[i])%mod;
  }
  cout<<dp[n-1];
  return 0;
}