#include<bits/stdc++.h>
using namespace std;
#define mod 998244353
typedef long long ll;
struct Interval  
{  
    ll s, e;  
};  
  

bool mycomp(Interval a, Interval b)  
{ 
return a.s < b.s; 
}  
  
vector<ll> mergeIntervals(Interval arr[], ll n)  
{  
    // Sort llervals in increasing order of 
    // start time 
    sort(arr, arr+n, mycomp);  
  
    ll index = 0; // Stores index of last element  
    // in output array (modified arr[])  
  
    // Traverse all input llervals  
    for (ll i=1; i<n; i++)  
    {  
        // If this is not first llerval and overlaps  
        // with the previous one  
        if (arr[index].e >=  arr[i].s)  
        {  
               // Merge previous and current llervals  
            arr[index].e = max(arr[index].e, arr[i].e);  
            arr[index].s = min(arr[index].s, arr[i].s);  
        }  
        else { 
            index++; 
            arr[index] = arr[i];  
        }     
    }  
  
    vector<ll> steps;  
    
    for (ll i = 0; i <= index; i++)
	{  
		for(ll j=arr[i].s;j<=arr[i].e;j++)
    	steps.push_back(j);
		
	}
	return steps;
          
}  
  
// Driver program  

ll numWays(ll n,vector<ll>steps)
{
	ll dp[n+1]={0};
	dp[1]=1;
	for(ll i=1;i<=n;i++)
	{
		
		for(ll j=0;j<steps.size();j++)
		{
			ll d=steps[j];
			if(i-d>=1)
			{
				dp[i]=(dp[i]+dp[i-d])%mod;
			}
		}
	}
	return dp[n];
}
/*
ll dp[200001];
ll numWays(ll n,ll s,vector<ll> steps)
{
	if(s==n)
	return 1;
	
	if(s>n)
	return 0;
	
	if(dp[s]!=-1)
	return dp[s];
	
	ll ways=0;
	for(ll i=0;i<steps.size();i++)
	{
		ll d=steps[i];
		if(s+d<=n)
		{
			ways=(ways+numWays(n,s+d,steps))%mod;
		}
	}
	dp[s]=ways;
	return ways;
}
*/
int main()
{
	ll n;
	cin>>n;
	
	ll k;
	cin>>k;
	//vector<pair<ll,ll>>steps;
	Interval arr[k];
	for(ll i=0;i<k;i++)
	{
		cin>>arr[i].s>>arr[i].e;
	}
	
	vector<ll> steps=mergeIntervals(arr,k);
	
		cout<<numWays(n,steps);
}	
