#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back

#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define rep(i, n) for (int i = 0; i < (int)(n); ++ i)

const int mod = 998244353;

int n, K;
int l[15], r[15];
int dp[1 << 18], s[1 << 18];

int qry(int a, int b) {
	a = max(a, 1);
	if (b < a) return 0;
	return (s[b] + mod - s[a - 1]) % mod;
}

int main() {
	scanf("%d %d", &n, &K);
	rep(i, K) scanf("%d %d", &l[i], &r[i]);
	dp[1] = s[1] = 1;
	for (int i = 2; i <= n; ++ i) {
		rep(j, K) (dp[i] += qry(i - r[j], i - l[j])) %= mod;
		s[i] = (s[i - 1] + dp[i]) % mod;
	}
	printf("%d\n", dp[n]);
	return 0;
}
