N, M = map(int, input().split())

path = [([int(1e9 + 1)] * N) for i in range(N)]
DP = [0] * N

for _ in range(M):
    L, R, C = map(int, input().split())
    if path[L-1][R-1] > C:
        path[L-1][R-1] = C

for i in range(N-1):
    for j in range(N-1, i+1, -1):
        if path[i][j] < path[i][j-1]:
            path[i][j-1] = path[i][j]
        if path[i][j] < path[i+1][j]:
            path[i+1][j] = path[i][j]

DP[1] = path[0][1]
for i in range(2, N):
    l = [DP[j] + path[j][i] for j in range(1, i) if path[j][i] != int(1e9 + 1)]
    if len(l) == 0:
        print(-1)
        exit()    
    m = min(l)
    DP[i] = min(path[0][i], m)

print(DP[-1])