#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod=998244353;
int sum[200010],dp[200010];
pair<int,int>a[15];
signed main()
{
	int n,k,i,j;
	cin>>n>>k;
	for(i=1;i<=k;i++)
		cin>>a[i].first>>a[i].second;
	sort(a+1,a+k+1);
	dp[1]=1;
	for(i=2;i<=n;i++)
	{
		for(j=1;j<=k;j++)
			sum[j]=(sum[j]+mod+mod-dp[max(0ll,i-a[j].second-1)]+dp[max(0ll,i-a[j].first)])%mod;
		for(j=1;j<=k;j++)
			dp[i]=(dp[i]+sum[j])%mod;
	}
	cout<<dp[n]%mod;
	return 0;
}