import std.container;
import std.range;
import std.algorithm;
import std.array;
import std.string;
import std.conv;
import std.stdio;
import std.container;

void main() {
	enum long Mod = 998244353;
	long n, k;
	readf("%s %s\n", n, k);
	--n;

	long[] s;
	foreach (i;0..k) {
		long l, r;
		readf("%s %s\n", l, r);

		foreach (long j;l..r + 1) {
			s ~= j;
		}
	}
	s.sort;

	auto dp = new long[n + 1];
	dp[0] = 1;
	
	foreach (i;1..n + 1) {
		foreach (e;s) {
			if (e > i) {
				break;
			}
			dp[i] = (dp[i] + dp[i - e]) % Mod;
		}
	}

	dp[$ - 1].writeln;
}
