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(l, r):
        if dp[i] > dp[r] + c:
            dp[i] = dp[r] + c
        else:
            break

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