#include<bits/stdc++.h>
using namespace std;
const int N=998244353;
int n,k;
int l[21],r[21];
long long dp[200010];
long long add[200010];
inline int read()
{
	int num=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9') {if(ch=='-') f=-1; ch=getchar();}
	while(ch>='0'&&ch<='9') {num=(num<<1)+(num<<3)+ch-'0'; ch=getchar();}
	return num*f;
}
int main()
{
	n=read(),k=read();
	for(int i=1;i<=k;i++) l[i]=read(),r[i]=read();	
	dp[1]=1; add[1]=1;
	for(int i=2;i<=n;i++)
		for(int j=1;j<=k;j++)
			dp[i]=(dp[i]+add[max(0,i-l[j])]-add[max(i-r[j]-1,0)])%N,add[i]=(add[i-1]+dp[i])%N;
	printf("%lld",(dp[n]+N)%N);
	return 0;
}