Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N,M=MI()
    
    class StarrySkyTree:
        """ Starry Sky Tree(区間加算・区間最小(大)値取得) """

        def __init__(self, N, func, intv):
            """
            N:要素数
            func:計算式(maxなど)
            intv:単位元
            """
            self.intv = intv
            self.func = func
            LV = (N-1).bit_length()
            self.N0 = 2**LV
            self.data = [0]*(2*self.N0)
            self.lazy = [0]*(2*self.N0)

        # 伝搬される区間のインデックス(1-indexed)を全て列挙するgenerator
        def gindex(self, l, r):
            L = l + self.N0; R = r + self.N0
            lm = (L // (L & -L)) >> 1
            rm = (R // (R & -R)) >> 1
            while L < R:
                if R <= rm:
                    yield R
                if L <= lm:
                    yield L
                L >>= 1; R >>= 1
            while L:
                yield L
                L >>= 1

        # 遅延評価の伝搬処理
        def propagates(self, *ids):
            # 1-indexedで単調増加のインデックスリスト
            for i in reversed(ids):
                v = self.lazy[i-1]
                if not v:
                    continue
                self.lazy[2*i-1] += v; self.lazy[2*i] += v
                self.data[2*i-1] += v; self.data[2*i] += v
                self.lazy[i-1] = 0

        def update(self, l, r, x):
            """ 区間[l,r)の値にxを加算 """

            # 1. lazyの値は伝搬させない
            # 2. 区間[l,r)のdata, lazyの値を更新
            L = self.N0 + l; R = self.N0 + r
            while L < R:
                if R & 1:
                    R -= 1
                    self.lazy[R-1] += x; self.data[R-1] += x
                if L & 1:
                    self.lazy[L-1] += x; self.data[L-1] += x
                    L += 1
                L >>= 1; R >>= 1
            # 3. 更新される区間を部分的に含んだ区間のdataの値を更新 (lazyの値を考慮)
            for i in self.gindex(l, r):
                self.data[i-1] = self.func(self.data[2*i-1], self.data[2*i]) + self.lazy[i-1]

        def query(self, l, r):
            """ 区間[l,r)の最小(大)値を取得 """

            # 1. トップダウンにlazyの値を伝搬
            self.propagates(*self.gindex(l, r))
            L = self.N0 + l; R = self.N0 + r

            # 2. 区間[l, r)の最小(大)値を求める
            s = self.intv
            while L < R:
                if R & 1:
                    R -= 1
                    s = self.func(s, self.data[R-1])
                if L & 1:
                    s = self.func(s, self.data[L-1])
                    L += 1
                L >>= 1; R >>= 1
            return s

    inf=10**20
    sst = StarrySkyTree(N+1, max, -1*inf)
    lra=[[0,0,0]for _ in range(M)]
    lra.append([N+2,N+2,0])#番兵
    
    for i in range(M):
        lra[i][0],lra[i][1],lra[i][2]=MI()
        
    lra.sort(key=lambda x:x[1])
    
    
    #sst[i]はi桁目がビットの立っている最右である時のmax
    #lrのクエリはrまで来た時に，範囲内に加算
    sst.update(0,1,0)
    now=0#クエリ処理用
    
    for i in range(1,N+1):
        temp=sst.query(0,i)
        sst.update(i,i+1,temp)#とりあえず，[0,i)の最大値を入れておく
        while i>=lra[now][1]:
            sst.update(lra[now][0],lra[now][1]+1,lra[now][2])
            now+=1
            
    print(sst.query(0,N+1))

main()


Fixed submission:
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N,M=MI()

    class Lazysegtree:
        #RAQ
        def __init__(self, A, intv, initialize = True, segf = min):
            #区間は 1-indexed で管理
            self.N = len(A)
            self.N0 = 2**(self.N-1).bit_length()
            self.intv = intv
            self.segf = segf
            self.lazy = [0]*(2*self.N0)
            if initialize:
                self.data = [intv]*self.N0 + A + [intv]*(self.N0 - self.N)
                for i in range(self.N0-1, 0, -1):
                    self.data[i] = self.segf(self.data[2*i], self.data[2*i+1]) 
            else:
                self.data = [intv]*(2*self.N0)

        def _ascend(self, k):
            k = k >> 1
            c = k.bit_length()
            for j in range(c):
                idx = k >> j
                self.data[idx] = self.segf(self.data[2*idx], self.data[2*idx+1]) \
                + self.lazy[idx]
                
        def _descend(self, k):
            k = k >> 1
            idx = 1
            c = k.bit_length()
            for j in range(1, c+1):
                idx = k >> (c - j)
                ax = self.lazy[idx]
                if not ax:
                    continue
                self.lazy[idx] = 0
                self.data[2*idx] += ax
                self.data[2*idx+1] += ax
                self.lazy[2*idx] += ax
                self.lazy[2*idx+1] += ax
        
        def update(self, k, x):
            k = k + self.N0
            self.data[k] = x
            self._ascend(k)
        
        def query(self, l, r):
            L = l+self.N0
            R = r+self.N0
            Li = L//(L & -L)
            Ri = R//(R & -R)
            self._descend(Li)
            self._descend(Ri - 1)
            
            s = self.intv                                                              
            while L < R:
                if R & 1:
                    R -= 1
                    s = self.segf(s, self.data[R])
                if L & 1:
                    s = self.segf(s, self.data[L])
                    L += 1
                L >>= 1
                R >>= 1
            return s
        
        def add(self, l, r, x):
            L = l+self.N0
            R = r+self.N0

            Li = L//(L & -L)
            Ri = R//(R & -R)
            
            while L < R :
                if R & 1:
                    R -= 1
                    self.data[R] += x
                    self.lazy[R] += x
                if L & 1:
                    self.data[L] += x
                    self.lazy[L] += x
                    L += 1
                L >>= 1
                R >>= 1
            
            self._ascend(Li)
            self._ascend(Ri-1)
            
    sst=Lazysegtree([0]*(N+1), 0, True, max)
            
    la=[[]for _ in range(N+1)]
    
    for i in range(M):
        l,r,a=MI()
        la[r].append([l,a])
    
    
    #sst[i]はi桁目がビットの立っている最右である時のmax
    #lrのクエリはrまで来た時に，範囲内に加算
    
 
    for i in range(1,N+1):
        temp=sst.query(0,i)
        sst.add(i,i+1,temp)#とりあえず，[0,i)の最大値を入れておく
        
        for l,a in la[i]:
            sst.add(l,i+1,a)
        
            
    print(sst.query(0,N+1))

main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env pypy3
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N,M=MI()

    class Lazysegtree:
        #RAQ
        def __init__(self, A, intv, initialize = True, segf = min):
            #区間は 1-indexed で管理
            self.N = len(A)
            self.N0 = 2**(self.N-1).bit_length()
            self.intv = intv
            self.segf = segf
            self.lazy = [0]*(2*self.N0)
            if initialize:
                self.data = [intv]*self.N0 + A + [intv]*(self.N0 - self.N)
                for i in range(self.N0-1, 0, -1):
                    self.data[i] = self.segf(self.data[2*i], self.data[2*i+1]) 
            else:
                self.data = [intv]*(2*self.N0)

        def _ascend(self, k):
            k = k >> 1
            c = k.bit_length()
            for j in range(c):
                idx = k >> j
                self.data[idx] = self.segf(self.data[2*idx], self.data[2*idx+1]) \
                + self.lazy[idx]
                
        def _descend(self, k):
            k = k >> 1
            idx = 1
            c = k.bit_length()
            for j in range(1, c+1):
                idx = k >> (c - j)
                ax = self.lazy[idx]
                if not ax:
                    continue
                self.lazy[idx] = 0
                self.data[2*idx] += ax
                self.data[2*idx+1] += ax
                self.lazy[2*idx] += ax
                self.lazy[2*idx+1] += ax
        
        def update(self, k, x):
            k = k + self.N0
            self.data[k] = x
            self._ascend(k)
        
        def query(self, l, r):
            L = l+self.N0
            R = r+self.N0
            Li = L//(L & -L)
            Ri = R//(R & -R)
            self._descend(Li)
            self._descend(Ri - 1)
            
            s = self.intv                                                              
            while L < R:
                if R & 1:
                    R -= 1
                    s = self.segf(s, self.data[R])
                if L & 1:
                    s = self.segf(s, self.data[L])
                    L += 1
                L >>= 1
                R >>= 1
            return s
        
        def add(self, l, r, x):
            L = l+self.N0
            R = r+self.N0

            Li = L//(L & -L)
            Ri = R//(R & -R)
            
            while L < R :
                if R & 1:
                    R -= 1
                    self.data[R] += x
                    self.lazy[R] += x
                if L & 1:
                    self.data[L] += x
                    self.lazy[L] += x
                    L += 1
                L >>= 1
                R >>= 1
            
            self._ascend(Li)
            self._ascend(Ri-1)
            
    sst=Lazysegtree([0]*(N+1), 0, True, max)
            
    la=[[]for _ in range(N+1)]
    
    for i in range(M):
        l,r,a=MI()
        la[r].append([l,a])
    
    
    #sst[i]はi桁目がビットの立っている最右である時のmax
    #lrのクエリはrまで来た時に，範囲内に加算
    
 
    for i in range(1,N+1):
        temp=sst.query(0,i)
        sst.add(i,i+1,temp)#とりあえず，[0,i)の最大値を入れておく
        
        for l,a in la[i]:
            sst.add(l,i+1,a)
        
            
    print(sst.query(0,N+1))

main()


Fixed submission:
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N,M=MI()

    class Lazysegtree:
        #RAQ
        def __init__(self, A, intv, initialize = True, segf = min):
            #区間は 1-indexed で管理
            self.N = len(A)
            self.N0 = 2**(self.N-1).bit_length()
            self.intv = intv
            self.segf = segf
            self.lazy = [0]*(2*self.N0)
            if initialize:
                self.data = [intv]*self.N0 + A + [intv]*(self.N0 - self.N)
                for i in range(self.N0-1, 0, -1):
                    self.data[i] = self.segf(self.data[2*i], self.data[2*i+1]) 
            else:
                self.data = [intv]*(2*self.N0)

        def _ascend(self, k):
            k = k >> 1
            c = k.bit_length()
            for j in range(c):
                idx = k >> j
                self.data[idx] = self.segf(self.data[2*idx], self.data[2*idx+1]) \
                + self.lazy[idx]
                
        def _descend(self, k):
            k = k >> 1
            idx = 1
            c = k.bit_length()
            for j in range(1, c+1):
                idx = k >> (c - j)
                ax = self.lazy[idx]
                if not ax:
                    continue
                self.lazy[idx] = 0
                self.data[2*idx] += ax
                self.data[2*idx+1] += ax
                self.lazy[2*idx] += ax
                self.lazy[2*idx+1] += ax
        
        def update(self, k, x):
            k = k + self.N0
            self.data[k] = x
            self._ascend(k)
        
        def query(self, l, r):
            L = l+self.N0
            R = r+self.N0
            Li = L//(L & -L)
            Ri = R//(R & -R)
            self._descend(Li)
            self._descend(Ri - 1)
            
            s = self.intv                                                              
            while L < R:
                if R & 1:
                    R -= 1
                    s = self.segf(s, self.data[R])
                if L & 1:
                    s = self.segf(s, self.data[L])
                    L += 1
                L >>= 1
                R >>= 1
            return s
        
        def add(self, l, r, x):
            L = l+self.N0
            R = r+self.N0

            Li = L//(L & -L)
            Ri = R//(R & -R)
            
            while L < R :
                if R & 1:
                    R -= 1
                    self.data[R] += x
                    self.lazy[R] += x
                if L & 1:
                    self.data[L] += x
                    self.lazy[L] += x
                    L += 1
                L >>= 1
                R >>= 1
            
            self._ascend(Li)
            self._ascend(Ri-1)
            
    sst=Lazysegtree([0]*(N+1), 0, True, max)
            
    la=[[]for _ in range(N+1)]
    
    for i in range(M):
        l,r,a=MI()
        la[r].append([l,a])
    
    
    #sst[i]はi桁目がビットの立っている最右である時のmax
    #lrのクエリはrまで来た時に，範囲内に加算
    
 
    for i in range(1,N+1):
        temp=sst.query(0,i)
        sst.add(i,i+1,temp)#とりあえず，[0,i)の最大値を入れておく
        
        for l,a in la[i]:
            sst.add(l,i+1,a)
        
            
    print(sst.query(0,N+1))

main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env pypy3
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N,M=MI()

    class Lazysegtree:
        #RAQ
        def __init__(self, A, intv, initialize = True, segf = min):
            #区間は 1-indexed で管理
            self.N = len(A)
            self.N0 = 2**(self.N-1).bit_length()
            self.intv = intv
            self.segf = segf
            self.lazy = [0]*(2*self.N0)
            if initialize:
                self.data = [intv]*self.N0 + A + [intv]*(self.N0 - self.N)
                for i in range(self.N0-1, 0, -1):
                    self.data[i] = self.segf(self.data[2*i], self.data[2*i+1]) 
            else:
                self.data = [intv]*(2*self.N0)

        def _ascend(self, k):
            k = k >> 1
            c = k.bit_length()
            for j in range(c):
                idx = k >> j
                self.data[idx] = self.segf(self.data[2*idx], self.data[2*idx+1]) \
                + self.lazy[idx]
                
        def _descend(self, k):
            k = k >> 1
            idx = 1
            c = k.bit_length()
            for j in range(1, c+1):
                idx = k >> (c - j)
                ax = self.lazy[idx]
                if not ax:
                    continue
                self.lazy[idx] = 0
                self.data[2*idx] += ax
                self.data[2*idx+1] += ax
                self.lazy[2*idx] += ax
                self.lazy[2*idx+1] += ax
        
        def update(self, k, x):
            k = k + self.N0
            self.data[k] = x
            self._ascend(k)
        
        def query(self, l, r):
            L = l+self.N0
            R = r+self.N0
            Li = L//(L & -L)
            Ri = R//(R & -R)
            self._descend(Li)
            self._descend(Ri - 1)
            
            s = self.intv                                                              
            while L < R:
                if R & 1:
                    R -= 1
                    s = self.segf(s, self.data[R])
                if L & 1:
                    s = self.segf(s, self.data[L])
                    L += 1
                L >>= 1
                R >>= 1
            return s
        
        def add(self, l, r, x):
            L = l+self.N0
            R = r+self.N0

            Li = L//(L & -L)
            Ri = R//(R & -R)
            
            while L < R :
                if R & 1:
                    R -= 1
                    self.data[R] += x
                    self.lazy[R] += x
                if L & 1:
                    self.data[L] += x
                    self.lazy[L] += x
                    L += 1
                L >>= 1
                R >>= 1
            
            self._ascend(Li)
            self._ascend(Ri-1)
            
    sst=Lazysegtree([0]*(N+1), 0, True, max)
            
    lra=[[0,0,0]for _ in range(M)]
    lra.append([N+5,N+5,0])#番兵
    
    for i in range(M):
        lra[i][0],lra[i][1],lra[i][2]=MI()
        
    lra.sort(key=lambda x:x[1])
    
    
    #sst[i]はi桁目がビットの立っている最右である時のmax
    #lrのクエリはrまで来た時に，範囲内に加算
    
    now=0#クエリ処理用
    
    for i in range(1,N+1):
        temp=sst.query(0,i)
        #print(i,temp)
        sst.add(i,i+1,temp)#とりあえず，[0,i)の最大値を入れておく
        #print(sst.get(i,i+1))
        while i>=lra[now][1]:
            sst.add(lra[now][0],lra[now][1]+1,lra[now][2])
            #print(i,lra[now][0],lra[now][1]+1,lra[now][2])
            now+=1
        """L=[]
        for j in range(N+1):
            L.append(sst.get(j,j+1))
        print(L)"""
            
    print(sst.query(0,N+1))

main()


Fixed submission:
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N,M=MI()

    class Lazysegtree:
        #RAQ
        def __init__(self, A, intv, initialize = True, segf = min):
            #区間は 1-indexed で管理
            self.N = len(A)
            self.N0 = 2**(self.N-1).bit_length()
            self.intv = intv
            self.segf = segf
            self.lazy = [0]*(2*self.N0)
            if initialize:
                self.data = [intv]*self.N0 + A + [intv]*(self.N0 - self.N)
                for i in range(self.N0-1, 0, -1):
                    self.data[i] = self.segf(self.data[2*i], self.data[2*i+1]) 
            else:
                self.data = [intv]*(2*self.N0)

        def _ascend(self, k):
            k = k >> 1
            c = k.bit_length()
            for j in range(c):
                idx = k >> j
                self.data[idx] = self.segf(self.data[2*idx], self.data[2*idx+1]) \
                + self.lazy[idx]
                
        def _descend(self, k):
            k = k >> 1
            idx = 1
            c = k.bit_length()
            for j in range(1, c+1):
                idx = k >> (c - j)
                ax = self.lazy[idx]
                if not ax:
                    continue
                self.lazy[idx] = 0
                self.data[2*idx] += ax
                self.data[2*idx+1] += ax
                self.lazy[2*idx] += ax
                self.lazy[2*idx+1] += ax
        
        def update(self, k, x):
            k = k + self.N0
            self.data[k] = x
            self._ascend(k)
        
        def query(self, l, r):
            L = l+self.N0
            R = r+self.N0
            Li = L//(L & -L)
            Ri = R//(R & -R)
            self._descend(Li)
            self._descend(Ri - 1)
            
            s = self.intv                                                              
            while L < R:
                if R & 1:
                    R -= 1
                    s = self.segf(s, self.data[R])
                if L & 1:
                    s = self.segf(s, self.data[L])
                    L += 1
                L >>= 1
                R >>= 1
            return s
        
        def add(self, l, r, x):
            L = l+self.N0
            R = r+self.N0

            Li = L//(L & -L)
            Ri = R//(R & -R)
            
            while L < R :
                if R & 1:
                    R -= 1
                    self.data[R] += x
                    self.lazy[R] += x
                if L & 1:
                    self.data[L] += x
                    self.lazy[L] += x
                    L += 1
                L >>= 1
                R >>= 1
            
            self._ascend(Li)
            self._ascend(Ri-1)
            
    sst=Lazysegtree([0]*(N+1), 0, True, max)
            
    la=[[]for _ in range(N+1)]
    
    for i in range(M):
        l,r,a=MI()
        la[r].append([l,a])
    
    
    #sst[i]はi桁目がビットの立っている最右である時のmax
    #lrのクエリはrまで来た時に，範囲内に加算
    
 
    for i in range(1,N+1):
        temp=sst.query(0,i)
        sst.add(i,i+1,temp)#とりあえず，[0,i)の最大値を入れておく
        
        for l,a in la[i]:
            sst.add(l,i+1,a)
        
            
    print(sst.query(0,N+1))

main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env pypy3
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N,M=MI()
    
    class StarrySkyTree:
        """ Starry Sky Tree(区間加算・区間最小(大)値取得) """

        def __init__(self, N, func, intv):
            """
            N:要素数
            func:計算式(maxなど)
            intv:単位元
            """
            self.intv = intv
            self.func = func
            LV = (N-1).bit_length()
            self.N0 = 2**LV
            self.data = [0]*(2*self.N0)
            self.lazy = [0]*(2*self.N0)

        # 伝搬される区間のインデックス(1-indexed)を全て列挙するgenerator
        def gindex(self, l, r):
            L = l + self.N0; R = r + self.N0
            lm = (L // (L & -L)) >> 1
            rm = (R // (R & -R)) >> 1
            while L < R:
                if R <= rm:
                    yield R
                if L <= lm:
                    yield L
                L >>= 1; R >>= 1
            while L:
                yield L
                L >>= 1

        # 遅延評価の伝搬処理
        def propagates(self, *ids):
            # 1-indexedで単調増加のインデックスリスト
            for i in reversed(ids):
                v = self.lazy[i-1]
                if not v:
                    continue
                self.lazy[2*i-1] += v; self.lazy[2*i] += v
                self.data[2*i-1] += v; self.data[2*i] += v
                self.lazy[i-1] = 0

        def update(self, l, r, x):
            """ 区間[l,r)の値にxを加算 """

            # 1. lazyの値は伝搬させない
            # 2. 区間[l,r)のdata, lazyの値を更新
            L = self.N0 + l; R = self.N0 + r
            while L < R:
                if R & 1:
                    R -= 1
                    self.lazy[R-1] += x; self.data[R-1] += x
                if L & 1:
                    self.lazy[L-1] += x; self.data[L-1] += x
                    L += 1
                L >>= 1; R >>= 1
            # 3. 更新される区間を部分的に含んだ区間のdataの値を更新 (lazyの値を考慮)
            for i in self.gindex(l, r):
                self.data[i-1] = self.func(self.data[2*i-1], self.data[2*i]) + self.lazy[i-1]

        def query(self, l, r):
            """ 区間[l,r)の最小(大)値を取得 """

            # 1. トップダウンにlazyの値を伝搬
            self.propagates(*self.gindex(l, r))
            L = self.N0 + l; R = self.N0 + r

            # 2. 区間[l, r)の最小(大)値を求める
            s = self.intv
            while L < R:
                if R & 1:
                    R -= 1
                    s = self.func(s, self.data[R-1])
                if L & 1:
                    s = self.func(s, self.data[L-1])
                    L += 1
                L >>= 1; R >>= 1
            return s

    inf=10**20
    sst = StarrySkyTree(N+1, max, -1*inf)
    lra=[[0,0,0]for _ in range(M)]
    lra.append([N+2,N+2,0])#番兵
    
    for i in range(M):
        lra[i][0],lra[i][1],lra[i][2]=MI()
        
    lra.sort(key=lambda x:x[1])
    
    
    #sst[i]はi桁目がビットの立っている最右である時のmax
    #lrのクエリはrまで来た時に，範囲内に加算
    sst.update(0,1,0)
    now=0#クエリ処理用
    
    for i in range(1,N+1):
        temp=sst.query(0,i)
        sst.update(i,i+1,temp)#とりあえず，[0,i)の最大値を入れておく
        while i>=lra[now][1]:
            sst.update(lra[now][0],lra[now][1]+1,lra[now][2])
            now+=1
            
    print(sst.query(0,N+1))

main()


Fixed submission:
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N,M=MI()

    class Lazysegtree:
        #RAQ
        def __init__(self, A, intv, initialize = True, segf = min):
            #区間は 1-indexed で管理
            self.N = len(A)
            self.N0 = 2**(self.N-1).bit_length()
            self.intv = intv
            self.segf = segf
            self.lazy = [0]*(2*self.N0)
            if initialize:
                self.data = [intv]*self.N0 + A + [intv]*(self.N0 - self.N)
                for i in range(self.N0-1, 0, -1):
                    self.data[i] = self.segf(self.data[2*i], self.data[2*i+1]) 
            else:
                self.data = [intv]*(2*self.N0)

        def _ascend(self, k):
            k = k >> 1
            c = k.bit_length()
            for j in range(c):
                idx = k >> j
                self.data[idx] = self.segf(self.data[2*idx], self.data[2*idx+1]) \
                + self.lazy[idx]
                
        def _descend(self, k):
            k = k >> 1
            idx = 1
            c = k.bit_length()
            for j in range(1, c+1):
                idx = k >> (c - j)
                ax = self.lazy[idx]
                if not ax:
                    continue
                self.lazy[idx] = 0
                self.data[2*idx] += ax
                self.data[2*idx+1] += ax
                self.lazy[2*idx] += ax
                self.lazy[2*idx+1] += ax
        
        def update(self, k, x):
            k = k + self.N0
            self.data[k] = x
            self._ascend(k)
        
        def query(self, l, r):
            L = l+self.N0
            R = r+self.N0
            Li = L//(L & -L)
            Ri = R//(R & -R)
            self._descend(Li)
            self._descend(Ri - 1)
            
            s = self.intv                                                              
            while L < R:
                if R & 1:
                    R -= 1
                    s = self.segf(s, self.data[R])
                if L & 1:
                    s = self.segf(s, self.data[L])
                    L += 1
                L >>= 1
                R >>= 1
            return s
        
        def add(self, l, r, x):
            L = l+self.N0
            R = r+self.N0

            Li = L//(L & -L)
            Ri = R//(R & -R)
            
            while L < R :
                if R & 1:
                    R -= 1
                    self.data[R] += x
                    self.lazy[R] += x
                if L & 1:
                    self.data[L] += x
                    self.lazy[L] += x
                    L += 1
                L >>= 1
                R >>= 1
            
            self._ascend(Li)
            self._ascend(Ri-1)
            
    sst=Lazysegtree([0]*(N+1), 0, True, max)
            
    la=[[]for _ in range(N+1)]
    
    for i in range(M):
        l,r,a=MI()
        la[r].append([l,a])
    
    
    #sst[i]はi桁目がビットの立っている最右である時のmax
    #lrのクエリはrまで来た時に，範囲内に加算
    
 
    for i in range(1,N+1):
        temp=sst.query(0,i)
        sst.add(i,i+1,temp)#とりあえず，[0,i)の最大値を入れておく
        
        for l,a in la[i]:
            sst.add(l,i+1,a)
        
            
    print(sst.query(0,N+1))

main()