import sys
input = sys.stdin.buffer.readline
import numpy as np
from operator import itemgetter

def main():
    N,M = map(int,input().split())
    root = [list(map(int,input().split())) for _ in range(M)]
    
    root.sort(key=itemgetter(0))
    d = [10**18 for _ in range(N)]
    d[0] = 0
    d = np.array(d)
    for l,r,c in root:
        if d[l-1] == 10**18:
            print(-1)
            exit()
        else:
            d[l:r] = np.minimum(d[l:r],d[l-1]+c)
            
    print(d[-1])

if __name__ == "__main__":
    main()