n, m = map(int,input().split())

ans = [-1] * (n + 1)
ll = []
for i in range(m):
    l, r, c = map(int,input().split())
    ll.append([l, r, c])
ll.sort()

for l, r, c in ll:
    if l == 1:
        for i in range(l + 1, r + 1):
            if ans[i] == -1:
                ans[i] = c
            else:
                if c < ans[i]:
                    ans[i] = c
    else:
        if ans[l] != -1:
            for i in range(l + 1, r + 1):
                if ans[i] == -1:
                    ans[i] = ans[l] + c
                else:
                    if c + ans[l] < ans[i]:
                        ans[i] = c + ans[l]
print(ans[-1])