#include<bits/stdc++.h>
using namespace std;
int read() {
	int x = 0,f = 0;char ch = getchar();
	while(!isdigit(ch)) {if(ch == '-') f = 1;ch = getchar();}
	while(isdigit(ch)) {x = x*10 + ch - '0';ch = getchar();}
	return f?-x:x;
}
const int N = 2e5 + 100,p = 998244353;
#define LL long long 
LL n,m,t[N],A[12],B[12];
LL ask(LL x) {
	LL tot = 0;
	for(LL i = x;i;i-=i&-i) tot = (tot + t[i]) % p;
	return tot;
}
void add(LL x,LL d) {
	for(LL i = x;i <= n;i+=i&-i) t[i] = (t[i] + d + p) % p;
}
int main() 
{
	n = read();m = read();
	for(int i = 1;i <= m;i++) {
		A[i] = read(),B[i] = read();
		if(A[i] > B[i]) swap(A[i],B[i]);
	} 
	add(1,1);add(2,-1);
	for(LL i = 1;i <= n;i++) {
		LL a = ask(i);
		if(!a) cont inue;
		for(LL j = 1;j <= m;j++) 
		{
			if(i + A[j] <= n) add(i + A[j],a);
			if(i + B[j] + 1 <= n) add(i + B[j] + 1,-a);
		}
	}
	cout << ask(n) << endl; 
	return 0;
}