import numpy as np
import collections
import sys
N, M  = map(int, input().split(' '))
graph = np.ones((N, N)) + 1e9
for i in range(M):
    L, R, C = map(int, input().split(' '))
    graph[L-1:R, L-1:R] = np.where(graph[L-1:R, L-1:R] > C, C, graph[L-1:R, L-1:R])
Ds = np.zeros(N)
for i in range(N-2, -1, -1):
    Ds[i] = (Ds[i+1:] + graph[i, i+1:]).min()
print(int(Ds[0]) if Ds[0] <= 1e9 else -1)

