output_description: Print the maximum possible score of a string.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N M
      l_1 r_1 a_1
      l_2 r_2 a_2
      :
      l_M r_M a_M
attempt: import sys
  
  input = sys.stdin.readline
  
  N, M = map(int, input().split())
  SCORE = [list(map(int, input().split())) for i in range(M)]
  
  SUM = [0] * (N + 2)
  start = [[] for i in range(N + 2)]
  end = [[] for i in range(N + 2)]
  
  for i in range(M):
      start[SCORE[i][0]].append(i)
      end[SCORE[i][1] + 1].append(i)
      SUM[SCORE[i][0]] += SCORE[i][2]
      SUM[SCORE[i][1] + 1] -= SCORE[i][2]
  
  import itertools
  
  SUM = list(itertools.accumulate(SUM))
  
  
  # 遅延Segment tree
  
  for i in range(30):  # 要素数以上の2のベキを見つける
      if N < 1 << i:
          seg_el = 1 << i  # Segment treeの台の要素数
          break
  
  seg_el2 = seg_el - 1  # Segment treeの一段目の最初の要素
  
  SEG = [0] * (2 * seg_el - 1)  # Segment tree
  LAZY = [0] * (2 * seg_el - 1)  # 子ノードへの伝搬用Segment tree
  
  
  def propagation(k):  # 子ノードへ伝搬
  
      if LAZY[k] != 0 and k < seg_el2:
          lazy_item = LAZY[k]
          LAZY[k] = 0
  
          LAZY[k * 2 + 1] += lazy_item
          LAZY[k * 2 + 2] += lazy_item
          SEG[k * 2 + 1] += lazy_item
          SEG[k * 2 + 2] += lazy_item
  
  
  def updates(a, b, x, k, l, r):  # 区間[a,b)にxを加算
      propagation(k)  # アクセスした箇所にデータが入っていたときは,評価を伝搬させる
  
      if r <= a or b <= l:  # 区間[a,b)が対象区間の外にあれば終了
          return
  
      if a <= l and r <= b:
          SEG[k] += x  # そのノードを更新
          LAZY[k] += x  # 後でアクセスされたときに子ノードを更新
          return
  
      updates(
          a, b, x, k * 2 + 1, l, (l + r) // 2
      )  # それ以外のときは,SEG[k*2+1]とSEG[k*2+2]で場合分け
      updates(a, b, x, k * 2 + 2, (l + r) // 2, r)
  
      if SEG[k * 2 + 1] > SEG[k * 2 + 2]:  # そのノードを更新（再帰的に値が求まる）
          SEG[k] = SEG[k * 2 + 1]
      else:
          SEG[k] = SEG[k * 2 + 2]
  
  
  def getvalues(
      a, b, k, l, r
  ):  # 区間[a,b)での,SEG[k],つまり区間[l,r)に関する最大値を調べる
  
      if r <= a or b <= l:  # 区間[a,b)が対象区間の外にあれば,-infを出力
          return -float("inf")
  
      if a <= l and r <= b:  # 区間[a,b)が対象区間の中にあればSEG[k]を出力
          return SEG[k]
  
      propagation(k)  # アクセスした箇所にデータが入っていたときは,評価を伝搬させる
  
      vl = getvalues(
          a, b, k * 2 + 1, l, (l + r) // 2
      )  # それ以外のときは,SEG[k*2+1]とSEG[k*2+2]で場合分け（木の子ノード二つを見る）
      vr = getvalues(a, b, k * 2 + 2, (l + r) // 2, r)
  
      if vl > vr:
          return vl
      else:
          return vr
  
  
  def update_solo(n, x, seg_el):  # A[n]+=xに更新（反映）
      i = n + seg_el - 1
      SEG[i] += x
      i = (i - 1) // 2
  
      while i >= 0:
          if SEG[i * 2 + 1] > SEG[i * 2 + 2]:
              SEG[i] = SEG[i * 2 + 1]
          else:
              SEG[i] = SEG[i * 2 + 2]
          i = (i - 1) // 2
  
  
  for i in range(1, N + 2):
  
      for j in start[i]:
          l, r, s = SCORE[j]
          updates(l, r + 1, -s, 0, 0, seg_el)
      for j in end[i]:
          l, r, s = SCORE[j]
          updates(l, r + 1, s, 0, 0, seg_el)
  
      # print(SEG)
  
      update_solo(i, getvalues(0, i, 0, 0, seg_el) + SUM[i], seg_el)
  
      # print(SEG)
  
  
  print(getvalues(0, N + 1, 0, 0, seg_el))
  
problem_description: Statement
  
  Consider a string of length N consisting of `0` and `1`. The score for the
  string is calculated as follows:
  
    * For each i (1 \leq i \leq M), a_i is added to the score if the string contains `1` at least once between the l_i-th and r_i-th characters (inclusive).
  
  Find the maximum possible score of a string.
samples: [{"input": "5 3\n    1 3 10\n    2 4 -10\n    3 5 10", "output": "20\n    \n\nThe score for `10001` is a_1 + a_3 = 10 + 10 = 20.\n\n* * *"}, {"input": "3 4\n    1 3 100\n    1 1 -10\n    2 2 -20\n    3 3 -30", "output": "90\n    \n\nThe score for `100` is a_1 + a_2 = 100 + (-10) = 90.\n\n* * *"}, {"input": "1 1\n    1 1 -10", "output": "0\n    \n\nThe score for `0` is 0.\n\n* * *"}, {"input": "1 5\n    1 1 1000000000\n    1 1 1000000000\n    1 1 1000000000\n    1 1 1000000000\n    1 1 1000000000", "output": "5000000000\n    \n\nThe answer may not fit into a 32-bit integer type.\n\n* * *"}, {"input": "6 8\n    5 5 3\n    1 1 10\n    1 6 -8\n    3 6 5\n    3 4 9\n    5 5 -2\n    1 3 -6\n    4 6 -7", "output": "10\n    \n\nFor example, the score for `101000` is a_2 + a_3 + a_4 + a_5 + a_7 = 10 + (-8)\n+ 5 + 9 + (-6) = 10."}]