from heapq import heappush, heappop

n, m = map(int, input().split())
edge = [list(map(int, input().split())) for _ in range(m)]
edge.sort()

q = []
for l, r, c in edge:
    # print(q)

    if l == 1:
        heappush(q, (r, c))
    else:
        q2 = []
        cand = float("inf")
        while q:
            y, z = heappop(q)

            if y < l:
                continue
            elif y < r:
                cand = min(cand, z)
                heappush(q2, (y, z))
            else:
                heappush(q2, (y, z))

        if cand != float("inf"):
            heappush(q2, (r, cand + c))

        q = q2
# print(q)

if len(q) == 0:
    ans = -1
else:
    ans = -1
    for y, z in q:
        if y == n:
            if ans == -1:
                ans = z
            else:
                ans = min(ans, z)

print(ans)
