#: Author - Soumya Saurav
import sys,io,os,time
from collections import defaultdict
from collections import Counter
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect,math,heapq
alphabet = "abcdefghijklmnopqrstuvwxyz"

input = sys.stdin.readline

########################################
import collections,sys,threading
sys.setrecursionlimit(10**9)
threading.stack_size(10**8)




def solve():
	from functools import lru_cache
	n , k = map(int, input().split())
	moves = set()
	for i in range(k):
		l , r = map(int, input().split())
		for j in range(l,r+1):
			moves.add(j)
	#print(moves)
	mod = 998244353
	@lru_cache(None)
	def f(curr):
		if curr > n:
			return 0
		if curr == n:
			return 1
		ans = 0
		for ele in moves:
			ans += f(curr + ele)
			ans = ans%mod
		return ans
	print(f(1))


threading.Thread(target=solve).start()




'''
# Wrap solution for more recursion depth
#submit as python3

'''
