#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const int MAX_N = 2e6+10;
ll dp[MAX_N];
int n, k;
int l[20], r[20];
const int MOD = 998244353;

void solve()
{
	dp[1]=1;
	dp[2]=-1;
	for(int i=1;i<=n;++i){
		(dp[i]+=dp[i-1])%=MOD;
		for(int j=0;j<k;++j){
			(dp[i+l[j]]+=dp[i])%=MOD;
			(dp[i+r[j]+1]-=dp[i]-MOD)%=MOD;
		}
	}
	cout<<dp[n]<<'\n';
}

int main()
{
	cin >> n >> k;
	for(int i=0;i<k;++i){
		cin >> l[i]>>r[i];
	}
	solve();
	return 0;
}