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)
dp=[10**14]*(N+1)
dp[0]=0
dp[1]=0
for e in ls:
  for i in range(e[0]+1,e[1]+1):
    dp[i]=min([dp[i],dp[e[0]]+e[2]])
#  print(dp)
print(dp[N]) 
  
