N, M = map(int, input().split())
lrc_list = []
for _ in range(M):
    lrc_list.append(tuple(map(int, input().split())))
lrc_list.sort()
way = [float('inf')] * N
way[0] = 0
for lrc in lrc_list:
    for i in range(lrc[0], lrc[1]):
        way[i] = min(way[i], way[lrc[0] - 1] + lrc[2])

if way[N - 1] != float('inf'):
    print(way[N - 1])
else:
    print(-1)
