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


main()
