

//BELIEVE IN YOURSELF
//next_permutation

#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define pob pop_back
#define vi vector<ll>
#define mp make_pair
#define sz size()
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define rep(i,n) for(ll i=0;i<n;i++)
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define maxx 100005
#define se second
#define fi first
#define be begin()
#define en end()
#define sortv(v) sort(v.begin(),v.end());
#define sortr(v) sort(v.rbegin(),v.rend());
#define w() ll _;cin>>_;while(_--)
#define edge pair<ll,ll>
#define pq priority_queue<ll>
#define mod 998244353
#define Endl "\n"
#define cy cout<<"YES"<<endl;
#define cn cout<<"NO"<<endl;
#define lb(v,x) std::lower_bound(v.begin(),v.end(),x)
#define ub(v,x) std::upper_bound(v.begin(),v.end(),x)

using namespace std;


int main()
{
	fast;
	
	ll n,k;
	cin>>n>>k;
	ll i,j;
	ll l,r;
	ll a[n]={0};
	vector<ll>v;
	for(i=0;i<k;i++)
	{
		cin>>l>>r;
		l--;
		r--;
		if(l==r)
		{
			v.pb(l+1);
		}
		a[l]+=1;
		a[r]-=1;
	}
	
	
	ll x=0;
	for(i=0;i<n;i++)
	{
		x+=a[i];
		if(x>0 || a[i]<0)
		{
			v.pb(i+1);
		}
	}
	
	ll m=v.size();
	sortv(v);
	
	ll dp[n+1]={0};
	dp[0]=0;
	dp[1]=1;
	
	for(i=2;i<=n;i++)
	{
		for(j=0;j<m;j++)
		{
			x=v[j];
			if(i-x<0)
			{
				break;
			}
			dp[i]=(mod+dp[i]+dp[i-x])%mod;
		}
	}
	
	cout<<dp[n]%mod<<endl;
	
		
	return 0;
}