#include<bits/stdc++.h>
using namespace std;
long long f[200001],c[20],a[200001],b[200001];
const int mod=998244353;
int main()
{
	int n,m;
	cin>>n>>m;
	for (int i=0;i<m;i++)
	 cin>>a[i]>>b[i];
	f[1]=1;
	for (int i=2;i<=n;i++)
	{
		for (int j=0;j<m;j++)
		 {
		 	c[j]+=(i-a[j]>=1?f[i-a[j]]:0)-(i-b[j]-1>=1?f[i-b[j]-1]:0);
		 	f[i]=(f[i]+c[j])%mod;
		 }
	}
	cout<<(f[n]+mod)%mod<<endl;
	return 0;
}