#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long 
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pb push_back
#define endl "\n"
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;  
#define mod 998244353
int main()
{
	ll n,k;
	cin>>n>>k;
	ll x,y;
	vector<ll> v;
	for(ll i=0;i<k;i++)
	{
		cin>>x>>y;
		for(ll j=x;j<=y;j++)
		{
			v.pb(j);
		}
	}
	sort(v.begin(), v.end());
	ll dp[n+1]={0};
	dp[n]=1;
	for(ll i=n-1;i>=1;i--)
	{
		for(ll j=0;j<v.size();j++)
		{
			if(i+v[j]<=n)
			{
				dp[i]=(dp[i]+dp[i+v[j]])%mod;
			}
			else
			{
				break;
			}
		}
	}
	cout<<dp[1];
}