#include<iostream>
using namespace std;
#define int long long
#define mod 998244353
int L[11],R[11];
int dp[200005];
int sum[200005];

signed main()
{
	std::ios::sync_with_stdio(false);
	cin.tie(0);
	int N,K;
	cin >> N >> K;
	for(int i = 1; i <= K; i++)
	{
		cin >> L[i] >> R[i];
	}
	sum[1] = dp[1] = 1;
	for(int i = 2; i <= N; i++)
	{
		for(int j = 1; j <= K; j++)
		{
			if(i - L[j] < 1)
			continue;
			else if(i- R[j] < 1)
			{
				dp[i] = (dp[i] + sum[i-L[j]])%mod;
			}
			else
			{
				dp[i] = (dp[i] + sum[i-L[j]])%mod;
				dp[i] = (dp[i] - sum[i-R[j]-1] + mod)%mod;
			}
		}
		sum[i] = (sum[i-1] + dp[i])%mod;
	}
	cout << dp[N] << endl;
}