#include <bits/stdc++.h>
#define int long long
using namespace std;
const int mod=998244353;

int n,k;
int l[1005],r[1005],dp[1000005],pre[2000005];

inline int query(int ll,int rr)
{
	return ((pre[rr]-pre[ll-1])%mod+mod)%mod;
}

signed main()
{
	cin>>n>>k;
	for (int i=1;i<=k;i++)  cin>>l[i]>>r[i];
	
	dp[1]=1;
	for (int i=1;i<=n;i++)
	{
		for (int j=1;j<=k;j++)
		{
			if (l[j]>=i)  continue;
			int nowr=min(r[j],i-1ll);
			dp[i]=(dp[i]+max(query(i-nowr,i-l[j]),0ll))%mod;
		}
		pre[i]=(pre[i-1]+dp[i])%mod;
	}
	cout<<dp[n]%mod<<endl;
	
	return 0;
}