#include<bits/stdc++.h>
const unsigned long long int M= 1000000007;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()	
#define fr(i,n) for(int i=0;i<n;i++)
#define pb push_back
#define int long long 
#define endl "\n"
using namespace std;
int power(int x,int y){int res=1;while(y>0){if(y&1)res=x*res; y=y>>1;x=x*x;}return res;}
int power(int x,int y,int mod){int res=1;while(y>0){if(y&1)res=x*res%mod; y=y>>1;x=x*x%mod;}return res;}

void nik()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL);

	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
	#endif
}

 	#define F first 
	#define S second 


signed main()
{	//nik();

		int test=1;
		//cin>>test;
		while(test--)
		{
		int n,k;
		cin>>n>>k;
		int l[k],r[k];
		int ans[n+1]={0},presum[n+1]={0};
		ans[1]=1;
		presum[1]=1;
		fr(i,k)
		{
			cin>>l[i]>>r[i];
		}
		int mod=998244353;
		for(int i=2;i<=n;i++)
		{
			fr(j,k)
			{
				int li=i-r[j];
				int ri=i-l[j];
				if(ri<0)continue;
				li=max(li,1ll);
				ans[i]+=(presum[ri]-presum[li-1]+mod)%mod;

			}
			presum[i]=(presum[i-1]+ans[i]+mod)%mod;
		}
		cout<<ans[n]+mod%mod;

		}
return 0;
}

