#!/usr/bin/python3
# -*- coding: utf-8 -*-
def dijkstra(s,n,m,cost):
    d = [float("inf")] * n
    used = [False] * n
    d[s] = 0
    d[1] = cost[0][1]
    for i in range(2, n):
        for j in range(0,i):
            if d[i] > d[j] + cost[j][i]:
                d[i] = d[j] + cost[j][i]
    return d[n - 1]

################################
n, m = map(int, input().split())
cost = [[float("inf") for i in range(n)] for i in range(n)]
for i in range(0, m):
    L, R, c = map(int, input().split())
    for j in range(L, R):
        for k in range(j, R):
            if cost[j - 1][k] > c:
                cost[j - 1][k] = c
result = dijkstra(0,n,m,cost)
if result == float("inf"):
    print(-1)
else:
    print(result)