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(' '))
    for s in range(L-1, R-1):
        for t in range(s+1, R):
            if graph[s, t] > C:
                graph[s, t] = C
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)

