import bisect
N,M=[int(s) for s in input().split()]
ls=[[int(s) for s in input().split()] for i in range(M)]
ls.sort()
#print(ls)
path=[[1,0]]
t=1
flag=0
for e in ls:
  if e[0]>t:
    print(-1)
    flag=1
    break
  else:
    k = bisect.bisect_left(path,[e[0],0])
    l = [e[1],path[k][1]+e[2]]
    k = bisect.bisect_left(path,l)
    path.insert(k, l)
    t=max([t,e[1]])
#    print(path)
if flag==0:
#  print(path)
  k=bisect.bisect_left(path,[N,0])
  print(path[k][1])
  
