N,K=input().split(' ')
N=int(N)
K=int(K)

mod=998244353
dp=[0]*(N)
dp[0]=1
S=set()

for x in range(0,K):
	a,b=input().split(' ')
	a=int(a)
	b=int(b)
	for y in range(a,b+1):
		S.add(y)

for x in range(1,N):
	for y in range(1,x+1):
		if y in S:
			dp[x]+=dp[x-y]

print(dp[N-1])