N, M = map(int, input().split())
LRCs = []
for i in range(M):
  L, R, C = map(int, input().split())
  L, R = L-1, R-1
  LRCs.append((L, R, C))
LRCs.sort()
#print(LRCs)
Ds = [-1]*N
Ds[0] = 0
for L, R, C in LRCs:
  for i in range(L, N):
    if not Ds[i] < 0:
      L = i
      break
  if Ds[L] < 0:
    continue
  if Ds[R] < 0:
    Ds[R] = Ds[L]+C
  else:
    Ds[R] = min(Ds[R], Ds[L]+C)
r = Ds[-1]
print(r)
