#include<bits/stdc++.h>
using namespace std;

typedef long long LL;

const int N=200000,mod=998244353;

int n,m,l[N+9],r[N+9];
int dp[N+9],sum[N+9];

void work(){
  scanf("%d%d",&n,&m);
  for (int i=1;i<=m;++i)
	scanf("%d%d",&l[i],&r[i]);
  dp[1]=sum[1]=1;
  for (int i=2;i<=n;++i){
	for (int j=1;j<=m;++j){
	  //printf("%d : %d %d\n",i,l[j],r[j]);
	  if (i-l[j]>=1) dp[i]=(dp[i]+sum[i-l[j]])%mod;
	  if (i-r[j]>=1) dp[i]=(dp[i]-sum[i-r[j]-1]+mod)%mod;
	}
	sum[i]=(dp[i]+sum[i-1])%mod;
  }
  printf("%d\n",dp[n]);
}

int main(){
  int T=1;
  for (;T--;) work();
  return 0;
}