#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define mp make_pair
#define pb push_back
#define pll pair<ll,ll>

ll INF = 998244353;


//-----------------//
  #define amin main
//-----------------//


int amin()
{
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t,i,j;
	ll n,k;
	cin>>n>>k;
	set<ll>vis;
	for(j=0;j<k;j++)
	{
		ll a,b;
		cin>>a>>b;
		for(i=a;i<=b;i++)
		{
			vis.insert(i);
		}
	}
	ll dp[n+3]={0};
	dp[0]=1;
	dp[1]=0;
	vector<ll>ans;
	for(auto itr=vis.begin();itr!=vis.end();itr++)
	{
		ans.pb(*itr);
	}
	for(i=0;i<ans.size();i++)
	{
		dp[ans[i]+1]=1;
		//cout<<ans[i]<<" ";
	}
	sort(ans.begin(),ans.end());
	//cout<<endl;
	for(i=1;i<=n;i++)
	{
		for(j=0;j<ans.size();j++)
		{
			if(i-ans[j]>0)
			{
				dp[i] += dp[i-ans[j]];
				if(dp[i]>=INF)
				dp[i] = dp[i]%INF;
			}
			else
				break;

		}
	}
	cout<<dp[n]%INF<<endl;

	
	
	


	
	return 0;
}