# coding: utf-8
# Your code here!

import sys

n,m = list(map(int,input().split()))

pl = []
for _ in range(m):
    l,r,c = list(map(int,input().split()))
    pl.append((l-1,r-1,c))

dp = [float('inf') for i in range(n)]
dp[0] = 0
pl = sorted(pl)

for l,r,c in pl:
    for rr in range(r,l,-1):
        if dp[rr] > dp[l] + c:
            dp[rr] = dp[l] + c
        else:
            break

if dp[-1] == float('inf'):
    print(-1)
else:
    print(dp[-1])