N, M = map(int,input().split())
LRC = list(list(map(int,input().split()))for i in range(M))
LRC.sort()
DP = [float('inf')]*N
DP[0] = 0
R = 0
for l,r,c in LRC:
    l -= 1
    r -= 1
    for i in range(l+1,r+1):
        DP[i] = min(DP[l]+c,DP[i])

if DP[-1] == float('inf'):
    print(-1)
else:
    print(DP[-1])