
#include <bits/stdc++.h>
#define ll long long int
#define all(x) x.begin(), x.end()
using namespace std;
ll power(ll x, ll y,ll  m) 
{ 
    if (y == 0) 
        return 1; 
    ll  p = power(x, y/2, m) % m; 
    p = (p * p) % m; 
  
    return (y%2 == 0)? p : (x * p) % m; 
} 
ll modInverse(ll a, ll m) 
{ 
    ll g = __gcd(a, m); 
    if (g != 1) 
        cout << "Inverse doesn't exist"; 
    
    
        // If a and m are relatively prime, then modulo inverse 
        // is a^(m-2) mode m 
        
              return power(a, m-2, m); 
    
} 

ll fact[1000];
void fac(ll m)
{
	ll i;
	fact[0]=1;
	for(i=1;i<1000;i++)
	{
		fact[i]=(i*fact[i-1])%m;
	}
}

ll comb(ll n,ll k,ll m)
{
	return(fact[n]*modInverse(fact[k],m)%m *modInverse(fact[n-k],m)%m)%m;
}
bool cmp(pair<ll,ll> a,pair<ll,ll>b)
{
	if(a.second==b.second)
	return a.first<b.first;
	return a.second>b.second;
}
void SieveOfEratosthenes(ll n) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
     bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (ll p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (ll i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
}
/*ll f(ll a)
{
ll i;ll res=1;ll c;
for(i=2;i*i<=a;i++)
{
	if(a%i==0)
	{
		c=0;
		while(a%i==0)
		{
			c++;
			a=a/i;
		}
		
	}
	if(c>0)
	{
		res*=(c+1);
	}
}
	if(a>1)
	{
		res*=2;
	}
		
	return res;
}*/
int main () {
ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 ll n,k;
 cin>>n>>k;
 ll mod=998244353;
 ll i;
 ll pre[100001]={0};
 ll dp[100001]={0};
 vector<pair<ll,ll>>a;
 for(i=0;i<k;i++)
 {
 	ll l,r;
	 cin>>l>>r;
	 a.push_back({l,r}); 
 }
 sort(all(a));
 dp[1]=1;
 pre[1]=1;ll j;
 for(i=2;i<=n;i++)
 {
 	for(j=0;j<k;j++)
 	{
 		if(a[j].first >i)
 		{
 			continue;
		 }
		 else if(a[j].second <i)
		 {
		 	dp[i]=(dp[i]+pre[i-a[j].first]-pre[i-a[j].second-1]+mod)%mod;
		 }
		 else
		 {
		 	dp[i]=(dp[i]+pre[i-a[j].first]-pre[0]+mod)%mod;
		 }
	 }
	 pre[i]=(pre[i-1]+dp[i])%mod;
 }
 
 cout<<dp[n]<<endl;
return 0;
}
