import numpy as np
n, m = map(int, input().split())
lrc = []
for _ in range(m):
    lrc.append(tuple(map(int, input().split())))
lrc.sort()

inf = 10**9
dp = np.ones(n, dtype=int)*inf
dp[0] = 1

for l, r, c in lrc:
    l -= 1
    r -= 1
    if dp[l] == 0:
        break
    d = dp[l] + c if l != 0 else c
    dp[l + 1: r + 1] = np.minimum(dp[l + 1: r + 1], d)

if dp[n - 1] == inf:
    ans = -1
else:
    ans = dp[n - 1]
print(ans)
