n, m = [int(v) for v in input().split(' ')]

costs = []
for i in range(n):
    costs.append([0] * i)

for i in range(m):
    l, r, c = [int(v) for v in input().split(' ')]

    for j in range(l, r):
        for k in range(j + 1, r + 1):
            c0 = costs[k - 1][j - 1]
            if c0 == 0 or c0 > c:
                costs[k - 1][j - 1] = c

import heapq
h = []
closed = 0

heapq.heappush(h, (0, n-1))

while len(h) > 0:
    c0, n1 = heapq.heappop(h)
    closed |= (1 << n1)

    if n1 == 0:
        print(c0)
        exit()

    for i in range(n):
        if i == n1:
            continue
        if closed & (1 << i) != 0:
            continue

        c1 = 0
        if i < n1:
            c1 = costs[n1][i]
        elif i > n1:
            c1 = costs[i][n1]
        if c1 > 0:
            heapq.heappush(h, (c0 + c1, i))

print("-1")