mod = 998244353
N,K = map(int,input().split())
move = []
for _ in range(K):
    x,y = map(int,input().split())
    for i in range(x,y+1):
        move.append(i)
move.sort()
move = set(move)
memo = [0]*(N+1)
memo[1] = 1
for i in range(1,N):
    if 0<memo[i]:
        for j in move:
            if i+j<=N:
                memo[i+j] += memo[i]
            else:
                break
        
print(memo[-1]%mod)