#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define ll long long
#define pr pair<int,int>
#define N 200005
#define mod 998244353
#define INF 998244353
using namespace std;
ll dp[N],l[N],r[N];
struct seg {
	ll l, r;
	bool operator <(seg& b) { return l < b.l; }
}a[N];
int main() {
	IOS;
	int n,k;
	cin >> n>>k;
	for (int i = 1; i <= k; i++) {
		cin >> a[i].l>>a[i].r;
	}
	sort(a + 1, a + 1 + k);
	dp[1] = 1;
	for (int i = 1; i < n; i++) {
		for (int j = 1; j <= k; j++) {
			if (a[j].l + i > n)
				break;
			for (int p = a[j].l; p <= a[j].r; p++) {
				int s = i + p;
				if (s > n)break;
				dp[s] = (dp[i] + dp[s]) % mod;
			}
		}
	}
	cout << dp[n] % mod;
	return 0;
}