N, M = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(M)]

INF = float("inf")
dp = [INF] * (N + 1)
dp[1] = 0
for l, r, c in sorted(X):
    for i in range(r, l, -1):
        if dp[i] > dp[l] + c:
            dp[i] = dp[l] + c
        else:
            break
            
print(dp[-1] if dp[-1] < INF else -1)

