import heapq

def main():
    n, m = map(int, input().split())
    dics = [{} for _ in range(n)]
    rmky = [set() for _ in range(n)]
    for _ in range(m):
        l, r, c = map(int, input().split())
        ky = (l-1, r-1)
        if ky in dics[l-1]:
            if c < dics[l-1][ky]:
                dics[l-1][ky] = c
        else:
            dics[l-1][ky] = c
        if r < n:
            rmky[r].add(ky)
    for i in range(1, n):
        dics[i].update(dics[i-1])
        for v in rmky[i]:
            dics[i].pop(v)
    dist = [float("inf")]*n
    dist[0] = 0
    hq = []
    heapq.heappush(hq, [0, 0])
    while len(hq) > 0:
        v, p = heapq.heappop(hq)
        if v > dist[p]:
            continue
        if p == n-1:
            break
        for l, r in dics[p].keys():
            if dist[r] > v + dics[p][(l, r)]:
                heapq.heappush(hq, [v + dics[p][(l, r)], r])
            for i in reversed(range(l, r+1)):
                if dist[i] > v + dics[p][(l, r)]:
                    dist[i] = v + dics[p][(l, r)]
                else:
                    break
    if dist[n-1] == float("inf"):
        print(-1)
    else:
        print(dist[n-1])

if __name__ == "__main__":
    main()
