N, M = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(M)]

class SegTreeMin:
    def __init__(self, n, inf=10 ** 15):
        self.n = n
        n2 = 1
        while n2 < n:
            n2 <<= 1
        self.n2 = n2
        self.tree = [inf] * (n2 << 1)
        self.inf = inf
        
    def update(self, i, x):
        i += self.n2
        self.tree[i] = x
        while i > 1:
            x = min(x, self.tree[i ^ 1])
            self.tree[i >> 1] = x
            i >>= 1
            
    def get_min(self, a, b):
        result = self.inf
        q = [(1, 0, self.n2)]
        while q:
            k, l, r = q.pop()
            if a <= l and r <= b:
                result = min(result, self.tree[k])
                continue
                
            m = (l + r) // 2
            k <<= 1
            if a < m and l < b:
                q.append((k, l, m))
            if a < r and l < m:
                q.append((k + 1, m, r))
                
        return result

INF = float("inf")
seg_tree = SegTreeMin(N, INF)
seg_tree.update(0, 0)
X.sort()
for l, r, c in X:
    l -= 1
    r -= 1
    tmp = seg_tree.get_min(l, r)
    seg_tree.update(r, min(tmp + c, seg_tree.get_min(r, r + 1)))
ans = seg_tree.get_min(N - 1, N)
print(ans if ans != INF else -1)
