# -*- coding: utf-8 -*-

def solve():
    N, M = map(int,input().split())
    E = [tuple(map(int,input().split())) for _ in range(M)]
    V = [float('inf') for _ in range(N)]
    V[0]=0
    E.sort()
    h = 0
    for e in E:
        l,r,c = e
        if h < l:
            h = l-1
        for i in range(h,r):
            V[i] = min(V[i], V[h]+c)

    return str(V[-1]) if V[-1] != float('inf') else '-1'

if __name__ == '__main__':
    print(solve())
