#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int MAXN = 2e5 + 5;
const int MAXD = 10 + 5;
const int mod = 998244353;

int l[MAXN], r[MAXN];

ll f[MAXN], sum[MAXN];

int main(void)
{
	int n,d;
	scanf("%d%d",&n,&d);
	for(int i=1; i<=d; ++i)
		scanf("%d%d",&l[i],&r[i]);
	
	f[1] = sum[1] = 1;
	
	for(int i=2; i<=n; ++i)
	{
		for(int j=1; j<=d; ++j)
		{
			if(i - l[j] < 1) continue;
			
			f[i] = (f[i] + sum[i-l[j]] - sum[max(i-r[j],1)-1] + mod) %mod;
		}
		sum[i] = (sum[i-1] + f[i]) %mod;
	}
	printf("%lld",f[n]);
	return 0;
}