#include <cstdio>
#include <algorithm>
using namespace std;
#define Nmax 200010
#define GETMD(a) ((a)%998244353+998244353)%998244353
#define MD 998244353
int N;
int K;
int sg[13][2];
long long sm[Nmax];
long long F[Nmax];
int main()
{
	scanf("%d %d", &N, &K);
	for (int i = 0; i < K; i++)
	{
		scanf("%d %d", &sg[i][0], &sg[i][1]);
	}
	F[1] = 1;
	sm[1] = 1;
	for (int i = 2; i <= N; i++)
	{
		F[i] = 0;
		for (int j = 0; j < K; j++)
		{
			F[i] = GETMD(F[i] + sm[max(i-sg[j][0], 0)] - sm[max(0, i-sg[j][1]-1)]);
		}
		sm[i] = GETMD(sm[i-1] + F[i]);
	}
	printf("%lld\n", F[N]);
	
	return 0;
}