#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
const int mod=998244353;
int n,k,l[11],r[11];
ll f[200001],s[200001];
int main(){
	cin>>n>>k;
	n--;
	for(int i=1;i<=k;i++) cin>>l[i]>>r[i];
	s[0]=f[0]=1;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=k;j++){
			if(i<l[j]) continue;
			if(i<=r[j]) f[i]=(f[i]+s[i-l[j]])%mod;
			else f[i]=(f[i]+mod+s[i-l[j]]-s[i-r[j]-1])%mod;
		}
		s[i]=(s[i-1]+f[i])%mod;
	}
	cout<<f[n];
}