N, K = map(int,input().split())
s = []
for i in range(K):
    L, R = map(int,input().split())
    for i in range(L, R+1):
        s.append(i)


dp = [0] * (N+1)
dp[0] = 1
for a in s:
    dp[a] = 1
for i in range(1,N):
    if dp[i] > 0:
        for a in s:
            if i + a < N:
                dp[i+a] += dp[i]
                dp[i+a] %= 998244353

print(dp[N-1])