import sys

import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def search(i, d, w, reached, costs, N, moves):
    if reached[i]:
        return
    if i == N-1:
        costs.append(moves)

    for j in w[i]:
        reached[i] = True
        moves += d[i, j]
        search(j, d, w, reached, costs, N, moves)
        moves -= d[i, j]
        reached[i] = False


def main():
    N, M = map(int, readline().split())
    d = np.full([N, N], 10**10)
    # w = np.full([N, N], -1)  # 1 => i, j がつながっている
    w = [[] for _ in range(N)]

    for i in range(M):
        L, R, C = map(int, readline().split())
        L, R = L-1, R-1
        for j in range(L+1, R+1):
            d[L, j] = min(d[L, j], C)
            w[L].append(j)

    for i in range(len(w)):
        w[i] = list(set(w[i]))
    reached = [False]*N
    costs = []
    moves = 0
    search(0, d, w, reached, costs, N, moves)

    if costs == []:
        print(-1)
    else:
        print(min(costs))


main()
