import math

n, m = map(int, input().split())
segment = [(1, 1, 0), (n, n, 0)]
node = {(1, 1, 0): [], (n, n, 0): []}
for _ in range(m):
    l, r, c = map(int, input().split())
    node[(l, r, c)] = []
    for s, e, tar_c in segment:
        if s <= l <= e or s <= r <= e:
            if e < r:
                node[(s, e, tar_c)].append((l, r, c))
            elif r < e:
                node[(l, r, c)].append((s, e, tar_c))
    segment.append((l, r, c))
#print(node)

def bfs(l, r, c, ans):
    n_nodes = node[(l, r, c)]
    if r==n:
        return ans+c
    if n_nodes == []:
        return float("inf")
    else:
        return min([bfs(s, e, n_c, ans + c) for s, e, n_c in n_nodes])


ans = bfs(1, 1, 0, 0)
if math.isinf(ans):
    print(-1)
else:
    print(ans)