#include<bits/stdc++.h>
#define MOD 998244353
#define MAX 200005
using namespace std;
long long dp[MAX+1],rsq[MAX+1];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n,k;
	cin>>n>>k;
	vector<pair<int,int>> v; 
	for(int i=0,x,y;i<k;++i)
	{
		cin>>x>>y;
		v.push_back({x,y});
	}
	sort(v.begin(),v.end());
	dp[1] = 1;
	rsq[1] = dp[1];
	for(int i=2;i<=n;++i)
	{
		rsq[i] = rsq[i-1];
		for(pair<int,int> p:v)
		{
			int x = p.first, y = p.second;
			if(i-x<=0)
				break;
			dp[i] += (rsq[i-x]-rsq[max(i-y,1)-1]+MOD)%MOD;
			dp[i] %= MOD;
		}
		rsq[i] += dp[i];
		rsq[i] %= MOD;
	}
	cout<<dp[n]<<endl;
	return 0;
}