N,M=map(int,input().split())

C=[[10**14]*N for i in range(N)]

D=[]
for i in range(M):
    D.append(list(map(int,input().split())))

D.sort(reverse=True,key=lambda x:x[2])

for l,r,d in D:
    l-=1
    r-=1
    for i in range(l,r):
        for j in range(i+1,r+1):
            C[i][j]=d

DP=[10**14]*N

DP[0]=0
temp=[]

for i in range(1,N):
    for j in range(0,i):
        temp.append(DP[j]+C[j][i])
    DP[i]=min(temp)
    temp=[]

if DP[N-1]>=10**14:
    print(-1)
else:
    print(DP[N-1])
