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