# coding: utf-8
# Your code here!
n,m=map(int,input().split())
INF = 10**15
dp = [INF]*(n-1)
dp.insert(0,0)

ls=[]

for i in range(m):
    l=list(map(int,input().split()))
    ls.append(l)

ls.sort()

for i in range(m):
    L=ls[i][0]
    R=ls[i][1]
    C=ls[i][2]
    for j in range(L,R):
        dp[j]=min(dp[j],dp[L-1]+C)
        
if dp[-1]==INF:
    ans=-1
else:
    ans=dp[-1]

print(ans)
    
