#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
#define N 200005
#define mod 998244353
#define rep(i, l, r) for(int i=l; i<=r; ++i)
using namespace std;
int t;
int n, k;
int l[11], r[11];
int f[N], s[N];
int main(){
	scanf("%d%d", &n, &k);
	rep(i, 1, k){
		scanf("%d%d", &l[i], &r[i]);
	}
	s[1]=f[1]=1;
	rep(i, 2, n){
		rep(j, 1, k){
			if(i>l[j]){
				if(i>r[j]) f[i]=((f[i]+s[i-l[j]]-s[i-r[j]-1])%mod+mod)%mod;
				else f[i]=(f[i]+s[i-l[j]])%mod;
			} 
		}
		//printf("%d %d\n", i, f[i]);
		s[i]=(s[i-1]+f[i])%mod;
	}
	printf("%d", f[n]);
	return 0;
}
	