mod = 998244353
N,K = map(int,input().split())
move = set()
for _ in range(K):
    x,y = map(int,input().split())
    for i in range(x,y+1):
        move.add(i)

memo = [0]*(N+1)
memo[1] = 1
for i in range(2,N+1):
    for j in move:
        if 0<i-j:
            memo[i] += memo[i-j]
    memo[i] = memo[i]%mod
print(memo[-1]%mod)