#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;
inline char nc() { static char buf[1000000], * p1 = buf, * p2 = buf; return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2) ? EOF : *p1++; }
inline void read(int& sum) { char ch = nc(); sum = 0; while (!(ch >= '0' && ch <= '9')) ch = nc(); while (ch >= '0' && ch <= '9') sum = (sum << 3) + (sum << 1) + (ch - 48), ch = nc(); }

ll dp[N];
struct seg {
	int l, r;
	bool operator <(seg& b) { return l < b.l; }
}a[N];
int main() {
	IOS;
	int n,k;
	read(n), read(k);
	for (int i = 1; i <= k; i++) {
		read(a[i].l), read(a[i].r);
	}
	sort(a + 1, a + 1 + k);
	dp[1] = 1;
	for (int i = 1; i < n; i++) {
		if (!dp[i])continue;
		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;
}