from operator import itemgetter
N,M = [int(x) for x in input().split()]
LRC = [[int(x) for x in input().split()] for _ in range(M)]
LRC.sort(key=itemgetter(0))
dist = [float('inf')] * N
dist[0] = 0
for l,r,c in LRC:
    fr = min(dist[l-1:r])
    for x in range(l-1,r):
        dist[x] = min(dist[x], fr+c)

if(dist[-1]==float('inf')):
    print(-1)
else:
    print(dist[-1])
