from collections import deque
import sys
N, M = list(map(int, input().split()))

RCL = []
for _ in range(M):
    L, R, C = list(map(int, input().split()))
    L -= 1
    R -= 1
    RCL.append((-R, C, L))
RCL.sort()

# if RCL[0][0] != -(N-1):
#    print(-1)
#    sys.exit(0)


D = deque()

for rcl in RCL:
    r, c, l = rcl
    r = -r
    if r == N-1:
        D.append((c, l))
    else:
        nex = deque()
        m = 10**16
        while D:
            d = D.popleft()
            if l < d[1] <= r:
                nex.append(d)
                if m > d[0] + c:
                    m = d[0] + c
        if m != 10**16:
            nex.append((m, l))
        D = nex

ans = 10**16

while D:
    d = D.popleft()
    if d[1] == 0 and ans > d[0]:
        ans = d[0]

if ans == 10**16:
    print(-1)
    sys.exit(0)
print(ans)
