N, M = map(int, input().split())
matrix = [[0] * (N+1) for i in range(N+1)]
min_distance = [0] * (N+1)
for i in range(M):
    L, R, C = map(int, input().split())
    for l in range(L,R):
        for r in range(l+1, R+1):
            if matrix[l][r] != 0:
                now = matrix[l][r]
                matrix[l][r] = min(now, C)
            else:
                matrix[l][r] = C
# print(matrix)

for i in range(1, N+1):
    for j in range(1, i):
        if min_distance[i] != 0 and matrix[j][i] != 0 and min_distance[j] != 0:
            min_distance[i] = min(min_distance[j] + matrix[j][i], min_distance[i])
        elif min_distance[i] == 0 and matrix[j][i] != 0 and min_distance[j] > 0:
            min_distance[i] = min_distance[j] + matrix[j][i]
        elif min_distance[i] == 0 and matrix[j][i] != 0 and j == 1:
            min_distance[i] = matrix[j][i]
        # print(i, j, min_distance[j], matrix[j][i], min_distance[i])

if min_distance[-1] == 0:
    print(-1)
else:
    print(min_distance[-1])