#include<bits/stdc++.h>
using namespace std;
typedef int64_t ll;
const ll MOD=998244353;
ll ans[400010],dif[400010];

int main(){
  ll n,k;
  cin>>n>>k;
  ll l[k],r[k];
  for(int i=0;i<k;i++)cin>>l[i]>>r[i];
  ans[0]=1;dif[1]=-1;
  for(int i=0;i<n;i++){
    for(int j=0;j<k;j++){
      dif[i+l[j]]+=ans[i];
      dif[i+l[j]]%=MOD;
      dif[i+r[j]+1]-=ans[i];
      dif[i+r[j]+1]+=MOD;
      dif[i+r[j]+1]%=MOD;
    }
    ans[i+1]=(ans[i]+dif[i+1])%MOD;
  }
  cout<<ans[n-1]<<endl;
}
