import sys
input = sys.stdin.readline
n,m=map(int,input().split())
LRC=[list(map(int,input().split())) for _ in range(n)]

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