import sys
input = sys.stdin.readline

n,m = map(int,input().split())
lrc = [list(map(int,input().split())) for _ in range(m)]

lrc.sort(key = lambda x:x[0])

dis = [-1] * n
dis[0] = 0

for i in range(m):
    if dis[lrc[i][0]-1] != -1:
        for j in range(lrc[i][0],lrc[i][1]):
            if dis[j] == -1:
                dis[j] = dis[lrc[i][0]-1] + lrc[i][2]
            else:
                dis[j] = min(dis[lrc[i][0]-1] + lrc[i][2], dis[j])

print(dis[-1])
