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:
    m=[f for f in path if f[0]>=e[0]]
    #print(m)
    path.append([e[1],m[0][1]+e[2]])
    t=max([t,e[1]])
    path.sort()
if flag==0:
  ans=[f for f in path if f[0]>=N]
  print(ans[0][1])
  
