N, M = map(int, input().split())
LRC = [list(map(int, input().split())) for i in range(M)]
LRC = sorted(LRC)
#print(LRC)
A = [10**16] * N
A[0] = 0

for i in range(M):
  L, R, C = LRC[i][0] - 1, LRC[i][1] - 1, LRC[i][2]
  if C < A[R] - A[L]:
    for j in range(L+1, R+1):
      A[j] = min(A[j], A[L] + C)

#出力
ans = A[-1]
if ans > 10 ** 15:
  ans = -1
  
print(ans)