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

d_set = set()

for k in range(K):
    L,R = map(int, input().split())
    d_set |= set(list(range(L,R+1)))

dp = [0] * (N+1)
# init
for d in d_set:
    dp[d] = 1

for i in range(N):
    for d in d_set:
        if i+d > N:
            break
        dp[i+d] += dp[i]

print(dp[N-1]%MOD)
