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[0], x[1]))
dis = [[1, 0]]
flag = True
for i in range(m):
    l = lrc[i][0]
    r = lrc[i][1]
    c = lrc[i][2]
    num = 0
    while dis[num][0] < l:
        num += 1
        if num == len(dis):
            flag = False
            break
    if flag == False:
        break
    temp_dis = []
    while dis[num][0] <= r:
        temp_dis.append(dis[num][1])
        num += 1
        if num == len(dis):
            break
    dis.append([r, min(temp_dis) + c])
    dis.sort()
if dis[-1][0] != n:
    print(-1)
else:
    num = -1
    while dis[num][0] == n:
        num -= 1
    print(dis[num + 1][1])