import sys
import heapq
input = sys.stdin.buffer.readline


def dijkstra(adj, start):
    # adj: [[to, cost] * vertices], 0th index must be empty
    dist = [float('inf')] * len(adj)
    dist[start] = 0
    q = []
    heapq.heappush(q, (0, start))
    while q:
        min_dist, v_from = heapq.heappop(q)
        if min_dist > dist[v_from]:
            continue
        v_tos = adj[v_from]
        for v_to, cost in v_tos:
            if min_dist + cost < dist[v_to]:
                dist[v_to] = min_dist + cost
                heapq.heappush(q, (dist[v_to], v_to))
    return dist


N, M = map(int, input().split())
adj = [[] for _ in range(N+1)]
for _ in range(M):
    L, R, C = map(int, input().split())
    adj[L].append((R, C))
for i in range(2, N+1):
    adj[i].append((i-1, 0))

dist = dijkstra(adj, 1)
# print(adj)
if dist[N] < 10**20:
    print(dist[N])
else:
    print(-1)
