n, m = map(int, input().split())
inf = 10 ** 15
dp = [inf for _ in range(n)]
edges = []
for _ in range(m):
    l, r, c = map(int, input().split())
    edges.append((l-1, r-1, c))

edges.sort(key=lambda x: x[0])

dp[0] = 0
for l, r, c in edges:
    for i in range(l+1, r+1):
        dp[i] = min(dp[i], dp[l] + c)

print(dp[n-1] if dp[n-1] < inf else -1)