#include<bits/stdc++.h>
#define MAXN 1000000+10
#define MOD 998244353

using namespace std;

int n,K;
long long Ans[MAXN];
int l[233],r[233];

int main()
{
	scanf("%d%d",&n,&K);
	for(int i=1;i<=K;i++)
		scanf("%d%d",&l[i],&r[i]);
	Ans[1] = 1;
	for(int i=2;i<=n;i++)
	{
		for(int j=1;j<=K;j++)
		{
			if(i<l[j]) continue;
			if(i>=r[j]) Ans[i] = (Ans[i] + (Ans[i-l[j]] - Ans[i-r[j]-1] + MOD)) % MOD;
			else Ans[i] = (Ans[i] + Ans[i-l[j]]) % MOD;
		}
		Ans[i] = (Ans[i] + Ans[i-1]) % MOD;
	}
	cout<<(Ans[n]-Ans[n-1]+MOD)%MOD;
	return 0;
}