#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll mod=998244353;
int main()
{
	ll i,j,k,m,n,t;
	cin>>n>>k;
	vector<pair<ll,ll>> v;
	for(i=0;i<k;i++)
	{
		ll  k1;
		cin>>j>>k1;
		v.push_back({j,k1});
	}
	ll ar[n],p[n];
	memset(ar,0,sizeof(ar));
	memset(p,0,sizeof(p));
	ar[0]=1;
	p[0]=1;
	for(i=1;i<n;i++)
	{
		for(auto x:v)
		{
			ll l=i-x.second;
			ll r=i-x.first;
			if(l<0 and r<0) continue;
			if(l<=0)
			ar[i]+=p[r];
			else
			{
				ll q=p[r]-p[l-1];
				if(q<0)
				q+=mod;
				else q%=mod;
				ar[i]+=q;
			}
			ar[i]%=mod;
		}
		p[i]=(p[i-1]+ar[i]%mod)%mod;
	}
	cout<<ar[n-1];
}