	#include<bits/stdc++.h>
	using namespace std;
	typedef long long ll;
	const int mod = 998244353;
	void solve(set<ll> coins,ll n)
	{
			n--;
	ll count[n+1];
	 memset(count,0,sizeof(count));
		count[0]=1;
		for(int i = 1;i<=n;i++)
		{
			for(auto c : coins)
			{
				if(i-(c)>=0)
				{
					count[i]+=count[i-c];
					count[i]=count[i]%mod;
				}
			}
		}
	printf("%lld\n",count[n]);
	}
	
	int main()
	{
	  ios::sync_with_stdio(0);
	  cin.tie(0);
	ll n ,k;
	scanf("%lld %lld",&n,&k);
	//vector<ll> v;
	//vector<vector<ll>> vec;
	set<ll> s;
	 for(int i = 0;i<k;i++)
	{
		ll l,r;
	scanf("%lld %lld",&l,&r);
		
		for(int j = l,j<=r;j++) s.insert(j);
		
		}
	
	  
	solve(s,n);
	}