N,K = map(int,input().split())
lis = [list(map(int,input().split())) for _ in range(K)]

T = []
oklis = [0]*(N+1)

for i in lis:
    for j in range(i[0],i[1]+1):
        oklis[j]=1

dp  = [0]*(N+1)
dp[1] = 1
MOD = 998244353

for i in range(2,N+1):
    for j in range(1,i+1):
        if oklis[j]==1:
            dp[i] += dp[i-j]
    dp[i] %= MOD

print(dp[N]%MOD)