#include <bits/stdc++.h>
using namespace std;
#define make_pair(a, b) mp(a, b)
typedef pair<int, int> pii; 
typedef long long ll;
const int maxn = 2e5 + 10;
const ll mod = 998244353;
ll f[maxn], g[maxn];
int n, k, l[20], r[20];
ll sum(int x) { return x > n ? 0 : g[x];}
int main()
{
	scanf("%d%d", &n, &k);
	for(int i = 1; i <= k; ++i) scanf("%d%d", &l[i], &r[i]);
	f[n] = 1; 
	g[n] = f[n];
	for(int i = n - 1; i; --i)
	{
		for(int j = 1; j <= k; ++j)
			f[i] = (f[i] + sum(i + l[j]) + mod - sum(i + r[j] + 1)) % mod;
		g[i] = (g[i + 1] + f[i]) % mod;
	}
	printf("%lld\n", f[1]);
	return 0;
}