N,M = map(int,input().split(' '))
LRC = []
for i in [0]*M:
    l,r,c= list(map(int,input().split(' ')))
    LRC.append((l,r,c))

INF = 10**20
d = [INF] * (N+1)
d[1] = 0
for i in range(2,N+1):
    for l,r,c in LRC:
        if not (l <= i <= r):
            continue
        for n in range(l,i):
            d[i] = min(d[n]+c, d[i])
if d[N] == INF:
    print(-1)
    exit()
print(d[N])
        

