#include <iostream>
using namespace std;
typedef long long ll;
  ll n,k;ll r=0;ll h[400005]={0};ll L[42]={0};ll M=998244353;
int main(){
  cin>>n>>k;h[1]=1;h[2]=-1;
  for(int i=0;i<k;i++)cin>>L[i+1]>>L[21+i];
  for(int i=1;i<n;i++){r+=h[i];if(r<0)r+=100*M;r%=M;
    for(int j=1;j<=k;j++){h[L[j]+i]+=r;h[L[20+j]+i+1]-=r;}
  }  cout<<((r+h[n])+100*M)%M<<endl;}