N, M = map(int, input().split())
inf = 10 * 9
dp = [inf for i in range(N + 1)]
dp[0] = 0
dp[1] = 0
LRC = [list(map(int,input().split())) for i in range(M)]
LRC.sort()
for i in range(M):
    L = LRC[i][0]
    R = LRC[i][1]
    C = LRC[i][2]
    for i in range(L + 1, R + 1):
        dp[i] = min(C + dp[L], dp[i])
        if i == 1:
            dp[1] = 0
if dp[N] == inf:
    print(-1)
    exit()
print(dp[N])