MOD = 998244353
N, K = map(int,input().split())
S = []
for k in range(K):
    L, R = map(int,input().split())
    for l in range(L,R+1):
        S.append(l)
S.sort()
dp = [0]*(N+1)
dp[1] = 1
for k in range(1,N+1):
    for e in S:
        if k+e <= N:
            dp[k+e] += dp[k]
            dp[k+e] %= MOD
        else:
            break
print(dp[N])
