import sys
import heapq
n, m = map(int, input().split())

nextL = [[] for _ in range(n+1)]
for i in range(2, n+1):
    nextL[i].append([i-1, 0])

INF = 10**18

costs = [INF] * (n+1)
costs[1] = 0

for i in range(m):
    l, r, c = map(int, sys.stdin.readline().split())
    nextL[l].append([r, c])

pc = []
heapq.heappush(pc, (0, 1))

unreach = set(range(1, n+1))

while len(pc) > 0 :
    cost, target = heapq.heappop(pc)
    if cost > costs[target]:
        continue
    for i in nextL[target]:
        nex = i[0]
        cos = i[1]
        if nex in unreach and cost + cos < costs[nex]:
            costs[nex] = cost + cos
            heapq.heappush(pc, (cost+cos, nex))
    unreach.remove(target)

if costs[n] == INF:
    print(-1)
else:
    print(costs[n])