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

dist.sort(key=lambda x:x[2])
dist.sort(key=lambda x:x[1])
dist.sort(key=lambda x:x[0])

res = [-1] * (n+1)
res[1] = 0
for i in dist:
    if res[i[0]] == -1:
        print(-1)
        exit()
    sh = res[i[0]] + i[2]
    if res[i[1]]!= -1 and  sh >= res[i[1]]:
        continue
    for j in range(i[0]+1, i[1]+1):
        if res[j] == -1 or res[j] > sh:
            res[j] = sh

print(res[n])