#include <stdio.h>
#include <math.h>
#include <string.h>

typedef long long ll;

int n, k;
int l[15], r[15];
int in_s[200005];
ll ans[200005];
ll ans_sum[15];
ll mod = 998244353;

ll getans(int x)
{
	if (x <= 0)
	{
		return 0;
	}
	if (ans[x] != -1)
	{
		return ans[x];
	}
	ll s = 0;
	for (int i = 0; i < k; i++)
	{
		s += getanssum(x - i);
		s %= mod;
	}
	ans[x] = s;
	return s;
	
}
ll getanssum(int ki)
{
	if (ans_sum[ki] != -1)
	{
		return ans_sum[ki];
	}
	ll s = 0;
	for (int i = k; i <= r; i++)
	{
		s += getans(i);
		s %= mod;
	}
	ans_sum[ki] = s;
	return s;
}

int main() {
	scanf("%d %d", &n, &k);
	for (int i = 0; i < k; i++)
	{
		scanf("%d %d", l[i], r[i]);
		for (int i = l; i <= r; i++)
		{
			in_s[i] = 1;
		}
		
	}
	for (int i = 0; i <= n; i++)
	{
		ans[i] = -1;
	}
	ans[1] = 1;
	for (int i = 0; i < k; i++)
	{
		ans_sum[i] = -1;
	}
	printf("%lld", getans(n));
	
	
	
	return 0;
}

