import sys
input = sys.stdin.readline


def main():
    N, M = map(int, input().split())
    A = []
    for _ in range(M):
        A.append(list(map(int, input().split())))
    A.sort(key=lambda x: x[0])
#    print(A)
    dp = [float("inf")]*N
    dp[0] = 0
    for (s, t, c) in A:
        for j in range(s, t+1):
            dp[j-1] = min(dp[j-1], dp[s-1] + c)
    ans = dp[N-1]
#    print(dp)
    if ans == float("inf"):
        print(-1)
    else:
        print(ans)


if __name__ == '__main__':
    main()
