#include<bits/stdc++.h>

using namespace std;

#define endl "\n"
#define lln long long int
#define IOS ios::sync_with_stdio(0);cin.tie(0);

const int MOD = 998244353;

int main(){
	IOS;

	int n,k;
	cin >> n >> k;
	vector<int> ans(n+1);
	set<int> moves;
	for(int i=0;i<k;i++){
		int x,y;
		cin >> x >> y;
		for(int j=x;j<=y;j++) moves.insert(j);
	}
	ans[1] = 1;
	for(int i=1;i<=n;i++){
		if(!a[i+j]) continue;
		for(auto j : moves){
			if(i+j<=n){
				ans[i+j] = (ans[i+j] + ans[i]) % MOD;
			}
		}
	}
	cout << ans[n] << endl;
	return 0;    
}