#include<bits/stdc++.h>
#define rep(i,x,y) for(int i=x,i##end=y;i<=i##end;++i)
#define _rep(i,x,y) for(int i=x,i##end=y;i>=i##end;--i)
#define ll long long
#define N 1000005
const int mod=998244353;
inline void reduce(int&x){x-=mod,x+=x>>31&mod;}
int dp[N],sum[N],n,k,L[N],R[N];
int main(){
	std::ios::sync_with_stdio(0);
	std::cin>>n>>k;
	rep(i,1,k) std::cin>>L[i]>>R[i];
	dp[1]=sum[1]=1;
	rep(i,2,n){
		rep(j,1,k){
			if(i-L[j]<=0) continue;
			int l=std::max(1,i-R[j]),r=i-L[j];
			reduce(dp[i]+=sum[r]);
			reduce(dp[i]+=mod-sum[l-1]);
		}
		sum[i]=sum[i-1];
		reduce(sum[i]+=dp[i]);
	}
	std::cout<<dp[n]<<'\n';
	return 0;
}