import sys
imput=sys.stdin.readline
n,m=map(int,input().split())
l=[list(map(int,input().split())) for i in range(m)]
l.sort()

dp=[[float('inf')]*(n+1) for i in range(m+1)]
for i in range(m+1):
    dp[i][0]=0;dp[i][1]=0
for i in range(1,m+1):
    dp[i]=dp[i-1]
    for j in range(l[i-1][0],l[i-1][1]+1):
        dp[i][j]=min(dp[i][j],dp[i-1][l[i-1][0]]+l[i-1][2])
if dp[-1][-1]==float('inf'):
    print(-1)
else:
    print(dp[-1][-1])
