import numpy as np
n,m=map(int,input().split())
a=sorted([list(map(int,input().split()))for i in range(m)])
s=np.array([float("INF")]*(n+1))
s[1]=0
for i in range(m):
    if a[i][0]!=1 and s[a[i][0]]==0:
        print(-1)
        break
    else:
        s[a[i][0]:a[i][1]+1]=np.minimum(s[a[i][0]:a[i][1]+1],s[a[i][0]]+a[i][2])
if s[-1]!=float("INF"):
    print(int(s[-1]))
else:
    print(-1)