N,M = map(int,input().split())
LRC = []
for _ in range(M):
    LRC.append(list(map(int,input().split())))
LRC.sort(key=lambda x: x[1])
LRC.sort(key=lambda x: x[0])

dp=[float('inf') for _ in range(N+10)]
dp[0] = 0
dp[1] = 0

for l,r,c in LRC:
    for d in range(r-l+1):
        dp[l+d] = min(dp[l]+c,dp[l+d])
print(dp[N])
