N, M = map(int, input().strip().split())
LRC = [list(map(int, input().strip().split())) for i in range(M)]
LRC.sort()
LRC = sorted(LRC, key=lambda h: (h[0], h[2]))
#print(LRC)

INF = -1
dp = [INF] * M
dp[0] = LRC[0][2]
for i in range(M):
    for j in range(i+1, M):
        if LRC[i][1] < LRC[j][0]:
            break
        if dp[j] == INF:
            dp[j] = dp[i] + LRC[j][2]
        else:
            dp[j] = min(dp[j], dp[i] + LRC[j][2])
#print(dp)
sol = -1
for i in range(M):
    if LRC[i][1] == N:
        if sol == -1:
            sol = dp[i]
        elif sol > dp[i]:
            sol = dp[i]
#print(dp)
print(sol)
