import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix

N, M = map(int, input().split())
graph = np.zeros((N, N))
for i in range(M):
    L, R, C = map(int, input().split())
    for s in range(L, R):
        for t in range(s+1, R+1):
            point = graph[s-1][t-1]
            if (point == 0.):
                graph[s-1][t-1] = C
            if C < graph[s-1][t-1]:
                graph[s-1][t-1] = C
print(int(shortest_path(csr_matrix(graph), indices=0, directed=False, method='BF')[-1]))
