import heapq
n, m = [int(i) for i in input().split()]
lrc = []
for _ in range(m):
    l, r, c = [int(i) for i in input().split()]
    lrc.append([l-1, r-1, c])
lrc.sort()
a = []
j = 0
for i in range(n):
    new = []
    while j < m and lrc[j][0] == i:
        new.append(lrc[j])
        j += 1
    if i == 0:
        now = 0
    else:
        while True:
            if len(a) == 0:
                print(-1)
                exit()
            now = heapq.heappop(a)
            if now[1] >= i:
                heapq.heappush(a, now)
                break
        now = now[0]
    for k in new:
        a.append([now + k[2], k[1]])
if len(a) == 0:
    print(-1)
else:
    while True:
        if len(a) == 0:
            print(-1)
            exit()
        now = heapq.heappop(a)
        if now[1] >= n-1:
            heapq.heappush(a, now)
            break
    now = now[0]
    print(now)
