#include<bits/stdc++.h>
using namespace std;
#define int 		  	long long
#define f(i,n)        	for(int i=0;i<(n);++i)
#define fa(i,a,n)     	for(int i=a;i<=(n);++i)
#define fd(i,a,n)     	for(int i=a;i>=(n);--i)
#define tc 			  	int t;cin>>t;f(testcase,t)
#define pii             pair<int,int>
#define allx 			x.begin(),x.end()
#define tr(c,i) 		for(auto i = c.begin(); i != c.end(); i++)
#define present(c,x) 	(c.find(x) != c.end())
#define cpresent(c,x) 	(find(allc,x) != c.end())
#define	PI 3.1415926535897932
#define M 998244353
void c_p_c() {

	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);

}
void solve() {
	int n, k;
	cin >> n >> k;
	set<int> s;
	f(i, k) {
		int x, y;
		cin >> x >> y;
		fa(j, x, y) {
			s.insert(j);
		}
	}
	vector<int> v;
	for (auto x : s) {
		v.push_back(x);
	}
	int a[n + 1] = {0};
	for (auto x : v) {
		if (x != n)
			a[x + 1] = 1;
	}
	fa(i, 1, n) {
		f(j, v.size())
		if (i - v[j] >= 1)
			a[i] = (a[i] + a[i - v[j]]) % M;

	}
	cout << a[n];
}

int32_t main() {

	c_p_c();
	//tc
	solve();
	return 0;
}

