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

inf = 10**18
dp = np.ones(n+1, dtype=np.int32)*inf
dp[n] = 0

for r, l, c in lrc:
    for i in range(r, 0, -1):
        if dp[i] != inf:
            break

    dp[l] = min(dp[l], dp[i] + c)


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