#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep3(i, s, n) for (int i = (s); i <= (int)(n); i++)

int a[200010];
int b[200010];
int lk[20];
int rk[20];

int main() {
	int n;
	int m;
	int k;
	int ans,lkk,rkk;
	long long p;

	m=998244353;
	a[1]=1;
	b[1]=1;

	cin >> n >> k ;
	rep(i, k) cin >> lk[i] >> rk[i] ;
	rep3(i,2,n+1){
		rep(j,k){
			rkk=max(i-rk[j]-1,0);
			lkk=max(i-lk[j],0);
			p=b[lkk]-b[rkk]+m;
			p%=m;
			a[i]+=p;
			a[i]%=m;
		}
		b[i]=b[i-1]+a[i];
		b[i]%=m;
	}
	ans=a[n]+m;
	ans%=m;

	cout << ans << endl;
	return 0;
}