import sys
from math import sqrt, gcd, ceil, log, floor
from bisect import bisect, bisect_left
from collections import defaultdict, Counter, deque
from heapq import heapify, heappush, heappop
input = sys.stdin.readline
read = lambda: list(map(int, input().strip().split()))

MOD = 998244353
def main():
	arr = []
	n, k = read()
	for _ in range(k):
		a, b = read()
		arr.extend(range(a, b+1))
	arr.sort()
	dp = defaultdict(int)
	dp[1] = 1
	for j in range(1, n+1):
		for i in arr:
			if j >= i:
				dp[j] += dp[j-i]
				dp[j] %= MOD
			else:
				break
		# print(i, dp)
	print(dp[n])

		



	

if __name__ == "__main__":
	main()
