N,M = (int(i) for i in input().split())
LRC = []

for i in range(M):
  LRC.append([int(i) for i in input().split()])

LRC.sort()

costs = [-1 for i in range(N+1)]
costs[0] = 0

for i in range(M):
  for j in range(LRC[i][0],LRC[i][1]+1):
    if LRC[i][0] == 1:
      # 1から飛べる範囲を設定
      if costs[j] == -1:
        costs[j] = LRC[i][2]
      else:
        costs[j] = min(costs[j],LRC[i][2])
    else:
      # そこまでに飛べる最小コストを調べ、そのコスト+現在のコストを行う
      min_costs = -1
      for k in range(LRC[i][0],j):
        if costs[k] >= 0:
          if min_costs == -1:
            min_costs = costs[k]
          else:
            min_costs = min(min_costs,costs[k])

      if min_costs != -1 and costs[j] == -1:
        costs[j] = min_costs + LRC[i][2]
      elif min_costs != -1 and costs[j] != -1:
        costs[j] = min(costs[j],min_costs + LRC[i][2])

ans = costs[N]
print(ans)
