#include<bits/stdc++.h>
using namespace std;
#define mod 998244353
typedef long long ll;

ll numWays(ll n,vector<ll> steps)
{
	ll dp[n+1]={0};
	dp[1]=1;
	for(ll i=1;i<=n;i++)
	{
		
		for(ll j=0;j<steps.size();j++)
		{
			ll d=steps[j];
			if(i-d>=1)
			{
				dp[i]=(dp[i]+dp[i-d])%mod;
			}
		}
	}
	return dp[n];
}
/*
ll dp[200001];
ll numWays(ll n,ll s,vector<ll> steps)
{
	if(s==n)
	return 1;
	
	if(s>n)
	return 0;
	
	if(dp[s]!=-1)
	return dp[s];
	
	ll ways=0;
	for(ll i=0;i<steps.size();i++)
	{
		ll d=steps[i];
		if(s+d<=n)
		{
			ways=(ways+numWays(n,s+d,steps))%mod;
		}
	}
	dp[s]=ways;
	return ways;
}
*/
int main()
{
	ll n;
	cin>>n;
	
	ll k;
	cin>>k;
	unordered_set<ll> sett;
	for(ll i=0;i<k;i++)
	{
		ll l,r;
		cin>>l>>r;
		for(ll j=l;j<=r;j++)
		sett.insert(j);
	}
	
	vector<ll> steps;
	for(auto it=sett.begin();it!=sett.end();it++)
	{
		steps.push_back(*it);
	}
		cout<<numWays(n,steps);
}	
