
mod =998244353

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

lr_list = []
for i in range(K):
    L, R = map(int,input().split())
    lr_list += list(range(L,R+1))
dp = [0]*N

min_lr_list = min(lr_list)

dp[min_lr_list] = 1

for i in range(min_lr_list+1,N):

    for j in lr_list:
        if i>j:
            dp[i] += dp[i-j]
            dp[i] %=mod
        elif i == j:
            dp[i] += 1
            dp[i] %=mod

print(dp[-1])
