#include<bits/stdc++.h>
#define ll long long
using namespace std;

const int mod = 998244353;
const int maxn = 200000 + 5;
ll f[maxn],a[maxn],b[maxn];
ll c[20];
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	
	for(int i = 0;i < m;++i)
		scanf("%d%d",&a[i],&b[i]);
	
	f[1] = 1;
	for(int i = 2;i <=n;++i)
		for(int j = 0;j < m;++j)
		{
			c[j] += (i - a[j] >= 1? f[i-a[j]] : 0) - (i - b[j] - 1>= 1 ? f[i-b[j] - 1] : 0);
			f[i] = (f[i] + c[j]) % mod;
		}
	cout<<f[n];
	return 0;
} 