N,M = list(map(int,input().split()))
import numpy as np

query = list()
for i in range(M):
  query.append(tuple(map(int,input().split())))
  
query.sort()
dp = np.zeros(N)
dp[1:] = np.inf
for l,r,c in query:
  dp[l-1:r] = np.minimum(dp[l-1]+c, dp[l-1:r])

print(int(dp[-1]) if dp[-1] != np.inf else -1)