# https://www.hackerrank.com/challenges/crush

n, m = input().split(' ')
n, m = int(n), int(m)

arr = [0]*n

for i in range(m):
    a, b, k = input().split(' ')
    a, b, k = int(a), int(b), int(k)
    arr[a-1] += k
    if b < n:
        arr[b] -= k
    
x = 0
max_x = 0
for elem in arr:
    x += elem
    if x > max_x:
        max_x = x
print(max_x)
        

94a848aa2fb6894d2276784486622cc6d02061c5
<mask token>

<mask token>
for i in range(m):
    a, b, k = input().split(' ')
    a, b, k = int(a), int(b), int(k)
    arr[a - 1] += k
    if b < n:
        arr[b] -= k
<mask token>
for elem in arr:
    x += elem
    if x > max_x:
        max_x = x
print(max_x)

n, m = input().split(' ')
n, m = int(n), int(m)
arr = [0] * n
for i in range(m):
    a, b, k = input().split(' ')
    a, b, k = int(a), int(b), int(k)
    arr[a - 1] += k
    if b < n:
        arr[b] -= k
x = 0
max_x = 0
for elem in arr:
    x += elem
    if x > max_x:
        max_x = x
print(max_x)

# https://www.hackerrank.com/challenges/crush

n, m = input().split(' ')
n, m = int(n), int(m)

arr = [0]*n

for i in range(m):
    a, b, k = input().split(' ')
    a, b, k = int(a), int(b), int(k)
    arr[a-1] += k
    if b < n:
        arr[b] -= k
    
x = 0
max_x = 0
for elem in arr:
    x += elem
    if x > max_x:
        max_x = x
print(max_x)
        
