#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5+13; 
const int mod= 998244353;
int dp[maxn];
int cal[maxn];
int l[maxn];
int r[maxn];
int main()
{
	int n,k;
	scanf("%d%d",&n,&k);
	for(int i=1;i<=k;i++)
	{
		scanf("%d%d",&l[i],&r[i]);
	}
	cal[1]=dp[1]=1;//到初始都是一种方法 
	for(int i=2;i<=n;i++)
	{
		for(int j=1;j<=k;j++)
		{
			dp[i]=(dp[i]+(cal[max(0,i-l[j])]-cal[max(0,i-r[j]-1)]))%mod;
			dp[i]=(dp[i]+mod)%mod;
			cal[i]=(cal[i-1]+dp[i])%mod;
		}
	}
	printf("%d",dp[n]);
	
 } 