from heapq import heappush, heappop
inf = float('inf')

# 計算量O((E+V)logV)
# 引数(始点,隣接リスト)
def dijkstra(start,ad):
    global dist
    #global cnt
    N = len(ad)
    dist = [inf] * N
    dist[start] = 0
    #cnt = [0] * N
    #cnt[start] = 1
    pq = [(dist[start], start)]
    while pq:
        dist_v, v = heappop(pq)
        for nv, nw in ad[v]:
            if dist[nv] > dist_v + nw:
                dist[nv] = dist_v + nw
                heappush(pq,(dist[nv], nv))
            #if dist[nv] == dist_v + nw:
                #cnt[nv] += cnt[v]
                #cnt[nv] %= mod

N, M = map(int,input().split())
to = [[] for _ in range(N)]
for _ in range(M):
    L, R, C = map(int,input().split())
    L -= 1; R -= 1
    to[L].append((R, C))

for i in range(1, N):
    to[i].append((i-1, 0))

dijkstra(0, to)

ans = dist[N-1]
if ans == inf:
    ans = -1
print(ans)