import sys

input = sys.stdin.readline

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

INF = 100100100100100100
dist = [INF]*N
dist[0] = 0

for li, ri, ci in LRC:
	for i in range(li,ri):
		dist[i] = min(dist[i], dist[li-1]+ci)

ans = dist[-1]
if ans==INF: ans = -1

print(ans)