# -*- coding: utf-8 -*-
from math import atan, pi
import sys
from collections import defaultdict
input = sys.stdin.readline
def inpl(): return list(map(int, input().split()))

class LazySegmentTree:
    
    def __init__(self, N, init_node=None, mode="min"):
        self.INF = 10**18
        
        if mode == "sum":
            self.aggfunc = lambda x, y: x+y
            self.lazyaddfunc = lambda x, l, r: x*(r-l)
            self.lazyfunc = lambda x: x//2
        
        elif mode == "max":
            self.aggfunc = lambda x, y: x if x > y else y
            self.lazyaddfunc = lambda x, l, r: x
            self.lazyfunc = lambda x: x
        
        elif mode == "min":
            self.aggfunc = lambda x, y: x if x > y else y
            self.lazyupdatefunc = lambda x, l, r: x
            self.lazyfunc = lambda x, y: min(x, y)
        
        self.size = 2**int.bit_length(N)
        self.node = [self.INF]*(2*self.size-1)
        if not init_node is None:
            for i in range(N):
                self.node[i+self.size-1] = init_node[i]
            for i in range(self.size-2, -1, -1):
                self.node[i] = min(self.node[2*i+1], self.node[2*i+2])
        self.lazy = [self.INF]*(2*self.size-1)
 
    def eval(self, k, l, r):
        if self.lazy[k] < self.INF:
            self.node[k] = min(self.node[k], self.lazy[k])
            if r-l-1:
                self.lazy[2*k+1] = min(self.lazy[2*k+1], self.lazy[k])
                self.lazy[2*k+2] = min(self.lazy[2*k+2], self.lazy[k])
            self.lazy[k] = self.INF*1

    def update(self, a, b, val):
        Q = [[0, 0, self.size]]
        Q2 = []
 
        def inner(k, l, r):
            nonlocal Q, Q2
            self.eval(k, l, r)
            if (b <= l) or (r <= a):
                return
            if (a<=l) and (r<=b):
                self.lazy[k] = min(self.lazy[k], val)
                self.eval(k, l, r)
            else:
                Q.append([2*k+1, l, (l+r)//2])
                Q.append([2*k+2, (l+r)//2, r])
                Q2.append(k)
 
        while Q:
            inner(*Q.pop())
        
        while Q2:
            k = Q2.pop()
            self.node[k] = min(self.node[2*k+1], self.node[2*k+2])
 
 
    def getagg(self, a, b):
        ix = 0
        Q = [[0, 0, self.size, 0]]
        Q2 = []
        S = [0]
 
        def inner(k, l, r, i):
            nonlocal ix, Q, Q2, S
            if (b<=l) or (r <= a):
                return 0
            self.eval(k, l, r)
            if (a<=l) and (r<=b):
                S[i] = self.node[k]
 
 
            else:
                Q.append([2*k+1, l, (l+r)//2, ix+1])
                Q.append([2*k+2, (l+r)//2, r, ix+2])
                Q2.append([ix, ix+1, ix+2])
                S.extend([0, 0])
                ix += 2
        while Q:
            inner(*Q.pop())
 
        while Q2:
            x, y, z = Q2.pop()
            S[x] = self.aggfunc(S[y], S[z])
        return S[0]

N, M = inpl()
init_node = [0] + [10**18]*(N-1)
LST = LazySegmentTree(N, init_node=init_node)
Q = [inpl() for _ in range(M)]
Q = sorted(Q, key=lambda x: x[0], reverse=True)
#print(*Q, sep="\n")

for i in range(N):
    v = LST.getagg(i, i+1)
    while len(Q) and (i == (Q[-1][0]-1)):
        l, r, c = Q.pop()
        LST.update(l-1, r, c+v)
        #print(*[LST.getagg(i, i+1) for i in range(N)], sep=" ")

ans = LST.getagg(N-1, N)
if ans == 10**18:
    print(-1)
else:
    print(ans)