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