D, N = map(int, input().split())
L, R, H = zip(*(map(int, input().split()) for _ in range(N)))

mw = [24 for _ in range(D)]

for i in range(N):
    for d in range(L[i] - 1, R[i]):
        mw[d] = min(mw[d], H[i])

print(sum(mw))

# O(ND)
