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

ll dp[500001];
const ll MOD =998244353;

int main()
{
	int n,k;
	cin >> n >> k;
	vector<int> l(k),r(k);
	for(int i = 0;i<k;i++)
	{
		cin >> l[i]>>r[i];
	}
	dp[0]=1;
	dp[1] = MOD-1;
	for(int i = 0;i<n;i++)
	{
		(dp[i+1] += dp[i])%=MOD;
		for(int j =0;j<k;j++)
		{
			(dp[i+l[j]]+= dp[i])%=MOD;
			(dp[i+r[j]+1] += MOD-dp[i])%=MOD;
		}
	}
	
	cout<<dp[n-1]<<endl;

	
}
