n, m = map(int, input().split())
lrc = []
for i in range(m):
    lrc.append(list(map(int, input().split())))
lrc.sort(key = lambda x: (x[1], x[2]))
lrc.sort()
dis = [[1, 0]]
num = 0
flag = True
for i in range(m):
    l = lrc[i][0]
    r = lrc[i][1]
    c = lrc[i][2]
    while dis[num][0] < l:
        num += 1
        if num == len(dis):
            flag = False
            break
    if flag == False:
        break
    dis.append([r, dis[num][1] + c])
    dis.sort()
if flag == False:
    print(-1)
else:
    num = -1
    dis2 = []
    while dis[num][0] == n:
        dis2.append(dis[num][1])
        num -= 1
    print(min(dis2))