N, M = map(int, input().split())
LRC = [list(map(int, input().split())) for _ in range(M)]
INF = 10 ** 10
LRC.sort()
dp = [INF] * (N+1) # dp[0]は使わない
dp[1] = 0
for l, r, c in LRC:
    x = dp[l] + c
    for i in range(r, l-1, -1):
        if dp[i] > x:
            dp[i] = x
        else:
            break
if dp[N] > INF:
    print(-1)
else:
    print(dp[N])
