#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int Mod=998244353,N=2e5+5;
const int INF=0x3f3f3f3f;
LL f[N],a[20],b[20],c[20];
int main() {
#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;++i){
		cin>>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]<<endl;
	return 0;
}
