#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ll long long
#define inf 0x3f3f3f3f
#define fast    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int N = 2e5+5;
const ll mod =   998244353;
ll n,k;
ll pre[N],dp[N];int l[30],r[30];
int main()
{  fast
cin>>n>>k;
for(int i=1;i<=k;i++)
cin>>l[i]>>r[i];
pre[1]=dp[1]=1;
for(int i=2;i<=n;i++){
for(int j=1;j<=k;j++){
	if(i<=l[j])continue;
	int x=l[j];
	int y=min(i-1,r[j]);
	(dp[i]+=(pre[i-x]-pre[i-y-1]+mod))%=mod;
	
}pre[i]=(pre[i-1]+dp[i])%mod;
}
cout<<dp[n];
}