#include<iostream>
#include<cstring>
#include<stdio.h>
#define int long long
using namespace std;
const int N=5e5,M=15,MOD=998244353;
int a[N];
int f[N];
int x[M],y[M];
int n,m;
int qzh[N];
inline modbez(int a,int b){
	register int res=a%b;
	if(res<0)
		return res+b;
	else
		return res;
}
void DP(){
	f[n]=1;
	for(int i=n;i>=1;i--){
		for(int j=1;j<=m;j++){
			f[i]=modbez(f[i]+qzh[i+x[j]]-qzh[i+y[j]+1],MOD);
//			cout<<i<<" "<<j<<" "<<qzh[i+x[j]]<<" "<<qzh[i+y[j]+1]<<" "<<qzh[i+x[j]]-qzh[i+y[j]+1]<<" "<<f[i]<<endl;
		}
		qzh[i]=modbez(qzh[i+1]+f[i],MOD);
//		cout<<"qzh "<<i<<" ="<<qzh[i]<<endl;
	}
//	for(int i=1;i<=n;i++)
//		cout<<qzh[i]<<" ";
//	cout<<endl;
//	for(int i=1;i<=n;i++){
//		cout<<f[i]<<" ";
//	}
//	cout<<endl;
	cout<<f[1]%MOD<<endl;
}
void common_DP(){//O(n^2)
	f[n]=1;
	for(int i=n;i>=1;i--)
		for(int j=1;j<=m;j++)
			for(int k=x[j];k<=y[j];k++){
				if(i+k<=n){
					f[i]=(f[i]+f[i+k])%MOD;
				}
			}
	cout<<f[1]<<endl;
}
signed main(){
	memset(f,0,sizeof(f));
	memset(a,0,sizeof(a));
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		cin>>x[i]>>y[i];
	}
	if(n>1e4)
		common_DP();
	else
		DP();
}








