N, M = map(int, input().strip().split())
LRC = [list(map(int, input().strip().split())) for i in range(M)]
LRC.sort()
#print(LRC)

INF = -1
dp = [INF] * (N+1)
dp[1] = 0
for i in range(1,N+1):
    if dp[i] == -1:
        continue
    for lrc in LRC:
        if lrc[0] > i:
            break
        for  j in range(i+1, lrc[1]+1):
            if dp[j] == INF:
                dp[j] = dp[i] + lrc[2]
            else:
                dp[j] = min(dp[j], dp[i] + lrc[2])
print(dp[N])
