# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N, C = map(int, input().split())
L = [list(map(int, input().split())) for _ in range(C)]
L = sorted(L, key=lambda x: (x[1], -x[2], x[0]), reverse=True)
dist = [float('inf')]*(N+1)
dist[-1] = 0
for l, r, c in L:
    for d in range(l, r):
        dist[d] = min(dist[r]+c, dist[d])
if dist[1] == float('inf'):
    print(-1)
else:
    print(dist[1])
