N,M=map(int,input().split())
datas=list(list(map(int,input().split())) for _ in range(M))
i1=0
i2=1
while i1!=i2:
  i1=i2
  i2=max(data[1] if data[0]<=i1 else 0 for data in datas)
if i2 != N:
  print(-1)
else:
  maximum=sum(data[2] for data in datas)
  shortest_path=list(list(0 for _1 in range(N)) for _2 in range(N))
  for i in range(N-2,-1,-1):
      shortest_path[i+1][i]=min(data[2] if data[0]<=i+1<data[1] else maximum for data in datas)
      for j in range(i+2,N,1):
          shortest_path[j][i]=min(min(data[2] if data[0]<=i+1 and j+1<=data[1] else maximum for data in datas),min(shortest_path[k][i]+shortest_path[j][k] for k in range(i+1,j,1)))
  print(shortest_path[N-1][0])