#!/bin/python3

import sys

if __name__ == "__main__":
    n, m = input().strip().split(' ')
    n, m = [int(n), int(m)]
    lst=[]
    for i in range(n):
        lst.insert(i,0)
    for a0 in range(m):
        a, b, k = input().strip().split(' ')
        a, b, k = [int(a), int(b), int(k)]
        if a >=0 and b >=0 and a <=n and b <=n:
            for i in range(a-1,b,1):
                lst[i] += k
        else:
            print("Error: Enter a and b values within index range of the list of size 'n'")
print(max(lst))
#Above method takes O(n*m) and times out in hacker rank

#using 'Accumulator' from itertools
from itertools import accumulate

n, m = map(int, input().split(' '))
dx = [0] * (n + 1) # allow run past end

for _ in range(m):
    a, b, c = map(int, input().split(' '))
    dx[a - 1] += c
    dx[b] -= c

print(max(accumulate(dx)))
