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[1])
    A.sort(key=lambda x: x[0])
    dp = [[float("inf")]*(N+1) for _ in range(M+1)]
    dp[0][0] = 0
    for i, (s, t, c) in enumerate(A):
        for j in range(s, t+1):
            dp[i+1][j-1] = min(dp[i][j-1], dp[i][s-1] + c)
    ans = dp[M][N-1]
    if ans == float("inf"):
        print(-1)
    else:
        print(ans)

if __name__ == '__main__':
    main()
