## coding: UTF-8


R,C,K = map(int,input().split())
rcv = []
for i in range(K):
    rcv.append(list(map(int,input().split())))

item = [0] * (R*C+1)
for i in range(K):
    index = (rcv[i][0] - 1) * C + (rcv[i][1] - 1) 
    #available[index] = True
    item[index] = rcv[i][2]

#print(item)



def solver(R,C,K):
    empty = []
    prev = []
    for i in range(C):
        empty.append([0] * 4)
        prev.append([0] * 4)
    
    for i in range(R):
        #print('prev', prev)
        now = []
        #ret = []
        zero = max(prev[0])
        now.append([zero, zero+item[i*C], 0, 0]) #一番左
        for j in range(1, C):
            index = i * C + j
            point = item[index]
            #print(i,j,index)
            ret = []
            left = now[-1]
            zero = max(left[0], max(prev[j])) #左からor上から
            ret.append(zero) #0
            one = max(zero + point, left[1]) #左からor上からきてアイテム取得 or 左から一個持った状態で拾わない
            two = max(left[1] + point, left[2])
            three = max(left[2] + point, left[3])
            ret.append(one)
            ret.append(two)
            ret.append(three)
            now.append(ret)
        prev = now
        #print(now)
    
    print(max(now[-1]))


solver(R,C,K)
 R,C,K = map(int,input().split()) R map(int,input().split()) map int input().split() ().split () input split C K rcv = [] rcv [] for i in range(K):
    rcv.append(list(map(int,input().split()))) i range(K) range K rcv.append(list(map(int,input().split()))) rcv.append rcv append list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split item = [0] * (R*C+1) item [0] * (R*C+1) [0] 0 R*C+1 R*C R C 1 for i in range(K):
    index = (rcv[i][0] - 1) * C + (rcv[i][1] - 1) 
    #available[index] = True
    item[index] = rcv[i][2]

#print(item) i range(K) range K index = (rcv[i][0] - 1) * C + (rcv[i][1] - 1) index (rcv[i][0] - 1) * C + (rcv[i][1] - 1) (rcv[i][0] - 1) * C rcv[i][0] - 1 rcv[i][0] [i] rcv i 0 1 C rcv[i][1] - 1 rcv[i][1] [i] rcv i 1 1 item[index] = rcv[i][2] item[index] item index rcv[i][2] [i] rcv i 2 def solver(R,C,K):
    empty = []
    prev = []
    for i in range(C):
        empty.append([0] * 4)
        prev.append([0] * 4)
    
    for i in range(R):
        #print('prev', prev)
        now = []
        #ret = []
        zero = max(prev[0])
        now.append([zero, zero+item[i*C], 0, 0]) #一番左
        for j in range(1, C):
            index = i * C + j
            point = item[index]
            #print(i,j,index)
            ret = []
            left = now[-1]
            zero = max(left[0], max(prev[j])) #左からor上から
            ret.append(zero) #0
            one = max(zero + point, left[1]) #左からor上からきてアイテム取得 or 左から一個持った状態で拾わない
            two = max(left[1] + point, left[2])
            three = max(left[2] + point, left[3])
            ret.append(one)
            ret.append(two)
            ret.append(three)
            now.append(ret)
        prev = now
        #print(now)
    
    print(max(now[-1])) solver empty = [] empty [] prev = [] prev [] for i in range(C):
        empty.append([0] * 4)
        prev.append([0] * 4)
    
     i range(C) range C empty.append([0] * 4) empty.append empty append [0] * 4 [0] 0 4 prev.append([0] * 4) prev.append prev append [0] * 4 [0] 0 4 for i in range(R):
        #print('prev', prev)
        now = []
        #ret = []
        zero = max(prev[0])
        now.append([zero, zero+item[i*C], 0, 0]) #一番左
        for j in range(1, C):
            index = i * C + j
            point = item[index]
            #print(i,j,index)
            ret = []
            left = now[-1]
            zero = max(left[0], max(prev[j])) #左からor上から
            ret.append(zero) #0
            one = max(zero + point, left[1]) #左からor上からきてアイテム取得 or 左から一個持った状態で拾わない
            two = max(left[1] + point, left[2])
            three = max(left[2] + point, left[3])
            ret.append(one)
            ret.append(two)
            ret.append(three)
            now.append(ret)
        prev = now
        #print(now)
    
     i range(R) range R now = [] now [] zero = max(prev[0]) zero max(prev[0]) max prev[0] prev 0 now.append([zero, zero+item[i*C], 0, 0]) now.append now append [zero, zero+item[i*C], 0, 0] zero zero+item[i*C] zero item[i*C] item i*C i C 0 0 for j in range(1, C):
            index = i * C + j
            point = item[index]
            #print(i,j,index)
            ret = []
            left = now[-1]
            zero = max(left[0], max(prev[j])) #左からor上から
            ret.append(zero) #0
            one = max(zero + point, left[1]) #左からor上からきてアイテム取得 or 左から一個持った状態で拾わない
            two = max(left[1] + point, left[2])
            three = max(left[2] + point, left[3])
            ret.append(one)
            ret.append(two)
            ret.append(three)
            now.append(ret)
         j range(1, C) range 1 C index = i * C + j index i * C + j i * C i C j point = item[index] point item[index] item index ret = [] ret [] left = now[-1] left now[-1] now -1 zero = max(left[0], max(prev[j])) zero max(left[0], max(prev[j])) max left[0] left 0 max(prev[j]) max prev[j] prev j ret.append(zero) ret.append ret append zero one = max(zero + point, left[1]) one max(zero + point, left[1]) max zero + point zero point left[1] left 1 two = max(left[1] + point, left[2]) two max(left[1] + point, left[2]) max left[1] + point left[1] left 1 point left[2] left 2 three = max(left[2] + point, left[3]) three max(left[2] + point, left[3]) max left[2] + point left[2] left 2 point left[3] left 3 ret.append(one) ret.append ret append one ret.append(two) ret.append ret append two ret.append(three) ret.append ret append three now.append(ret) now.append now append ret prev = now prev now print(max(now[-1])) print max(now[-1]) max now[-1] now -1 R R C C K K solver(R,C,K) solver R C K item = [0] * (R*C+1) [0] * (R*C+1) item C,K = map(int,input().split()) map(int,input().split()) C R,C,K = map(int,input().split()) map(int,input().split()) R K = map(int,input().split()) map(int,input().split()) K rcv = [] [] rcv index = (rcv[i][0] - 1) * C + (rcv[i][1] - 1) (rcv[i][0] - 1) * C + (rcv[i][1] - 1) index def solver(R,C,K):
    empty = []
    prev = []
    for i in range(C):
        empty.append([0] * 4)
        prev.append([0] * 4)
    
    for i in range(R):
        #print('prev', prev)
        now = []
        #ret = []
        zero = max(prev[0])
        now.append([zero, zero+item[i*C], 0, 0]) #一番左
        for j in range(1, C):
            index = i * C + j
            point = item[index]
            #print(i,j,index)
            ret = []
            left = now[-1]
            zero = max(left[0], max(prev[j])) #左からor上から
            ret.append(zero) #0
            one = max(zero + point, left[1]) #左からor上からきてアイテム取得 or 左から一個持った状態で拾わない
            two = max(left[1] + point, left[2])
            three = max(left[2] + point, left[3])
            ret.append(one)
            ret.append(two)
            ret.append(three)
            now.append(ret)
        prev = now
        #print(now)
    
    print(max(now[-1])) def solver(R,C,K):
    empty = []
    prev = []
    for i in range(C):
        empty.append([0] * 4)
        prev.append([0] * 4)
    
    for i in range(R):
        #print('prev', prev)
        now = []
        #ret = []
        zero = max(prev[0])
        now.append([zero, zero+item[i*C], 0, 0]) #一番左
        for j in range(1, C):
            index = i * C + j
            point = item[index]
            #print(i,j,index)
            ret = []
            left = now[-1]
            zero = max(left[0], max(prev[j])) #左からor上から
            ret.append(zero) #0
            one = max(zero + point, left[1]) #左からor上からきてアイテム取得 or 左から一個持った状態で拾わない
            two = max(left[1] + point, left[2])
            three = max(left[2] + point, left[3])
            ret.append(one)
            ret.append(two)
            ret.append(three)
            now.append(ret)
        prev = now
        #print(now)
    
    print(max(now[-1])) solver
## coding: UTF-8


R,C,K = map(int,input().split())
rcv = []
for i in range(K):
    rcv.append(list(map(int,input().split())))

item = [0] * (R*C+1)
for i in range(K):
    index = (rcv[i][0] - 1) * C + (rcv[i][1] - 1) 
    #available[index] = True
    item[index] = rcv[i][2]

#print(item)



def solver(R,C,K):
    empty = []
    prev = []
    for i in range(C):
        empty.append([0] * 4)
        prev.append([0] * 4)
    
    for i in range(R):
        #print('prev', prev)
        now = []
        #ret = []
        zero = max(prev[0])
        now.append([zero, zero+item[i*C], 0, 0]) #一番左
        for j in range(1, C):
            index = i * C + j
            point = item[index]
            #print(i,j,index)
            ret = []
            left = now[-1]
            zero = max(left[0], max(prev[j])) #左からor上から
            ret.append(zero) #0
            one = max(zero + point, left[1]) #左からor上からきてアイテム取得 or 左から一個持った状態で拾わない
            two = max(left[1] + point, left[2])
            three = max(left[2] + point, left[3])
            ret.append(one)
            ret.append(two)
            ret.append(three)
            now.append(ret)
        prev = now
        #print(now)
    
    print(max(now[-1]))


solver(R,C,K)

