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 itertools
  import bisect
  
  n, m = map(int, input().split())
  
  q = []
  for i in range(m):
      l, r, a = map(int, input().split())
      q.append([l - 1, r - 1, a])
  q.sort()
  
  left = []
  for l, r, a in q:
      left.append(l)
  
  left.append(float("inf"))
  
  # dp = [None] * (n + 2)
  # def dfs(i=-1):
  #     if dp[i] is not None:
  #         return dp[i]
  #
  #     if i == n:
  #         dp[i] = 0
  #         return dp[i]
  #
  #     dp[i] = max([dfs(j) + score(i + 1, j) for j in range(i + 1, n + 1)])
  #     return dp[i]
  
  t = 1
  while t < (n + 1):
      t *= 2
  seg = [0] * (t * 2 - 1)
  lazy = [0] * len(seg)
  up = lambda node: (node - 1) // 2
  down = lambda node: [(node * 2) + 1, (node * 2) + 2]
  
  
  def lazy_eval(node):
      if lazy[node]:
          value = lazy[node]
          lazy[node] = 0
          seg[node] += value
  
          if node < t - 1:
              children = down(node)
              lazy[children[0]] += value
              lazy[children[1]] += value
      return seg[node]
  
  
  def add(x, l, r, node=0, sl=0, sr=t):
      if sr <= l or r <= sl:
          return
  
      if l <= sl and sr <= r:
          lazy[node] += x
          return
  
      sc = (sl + sr) // 2
      c = down(node)
      add(x, l, r, c[0], sl, sc)
      add(x, l, r, c[1], sc, sr)
      seg[node] = max(lazy_eval(c[0]), lazy_eval(c[1]))
  
  
  prev = 0
  score_table = [0] * (n + 1)
  for i in reversed(range(-1, n)):
      left_start_index = bisect.bisect_left(left, i + 1)
      left_end_index = bisect.bisect_right(left, i + 1)
      for l, r, v in q[left_start_index:left_end_index]:
          seg[0] += 1
  
      add(prev, i + 1, i + 2)
      prev = lazy_eval(0)
  
  print(prev)
  
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."}]