N, M = map(int, input().split())
LRC = sorted([list(map(int, input().split())) for i in range(M)])

inf = float('inf')
dp = [inf] * (N+1)
dp[1] = 0
for l, r, c in LRC:
    for i in range(r, l, -1):
        if dp[i] > dp[l]+c:
            dp[i] = dp[l]+c
        else:
            break

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