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

V = []

for i in range(K):
    L,R = map(int,input().split())
    for j in range(L,R+1):
        V.append(j)

V.sort()

v = len(V)

dp = [0 for i in range(N+1)]

dp[1] = 1

for i in range(2,N+1):
    for j in range(v):
        if i - V[j] >= 1:
            dp[i] += (dp[i - V[j]])%MOD
        else:
            break

print(dp[-1]%MOD)