import sys
sys.setrecursionlimit(10000)

n, m = [int(x) for x in input().split()]
v = [ {} for x in range(n - 1)]
for i in range(m):
    (l, r, c) = [int(x) for x in input().split()]
    for a in range((l - 1), r, 1):
        for b in range((a + 1), r, 1):
            if (b in v[a]):
                if v[a][b] > c:
                    v[a][b] = c
            else:
                v[a][b] = c

def dp(v, st, end):
    if st == end:
        return 0
    elif v[st] == {}:
        return 10**20
    else:
        z = 10**20
        for k in v[st].keys():
            t = v[st][k] + dp(v, k, end)
            if z > t:
                z = t
        return z
            
cost = dp(v, 0, n-1)
print(cost if cost < 10**20 else -1)
