n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(m)]
a.sort()
dp = [10 ** 18 for i in range(n)]
dp[0] = 0
for l, r, c in a:
    for i in range(l - 1, r):
        dp[i] = min(dp[i], dp[l - 1] + c)
if dp[-1] == 10 ** 18:
    print(-1)
else:
    print(dp[-1])
