import sys,bisect,string,math,time,functools,random,fractions
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations,groupby
rep=range;R=range
def Golf():n,*t=map(int,open(0).read().split())
def I():return int(input())
def S_():return input()
def IS():return input().split()
def LS():return [i for i in input().split()]
def MI():return map(int,input().split())
def LI():return [int(i) for i in input().split()]
def LI_():return [int(i)-1 for i in input().split()]
def NI(n):return [int(input()) for i in range(n)]
def NI_(n):return [int(input())-1 for i in range(n)]
def StoLI():return [ord(i)-97 for i in input()]
def ItoS(n):return chr(n+97)
def LtoS(ls):return ''.join([chr(i+97) for i in ls])
def RA():return map(int,open(0).read().split())
def RLI(n=8,a=1,b=10):return [random.randint(a,b)for i in range(n)]
def RI(a=1,b=10):return random.randint(a,b)
def Rtest(T):
    case,err=0,0
    for i in range(T):
        inp=INP()
        a1,ls=naive(*inp)
        a2=solve(*inp)
        if a1!=a2:
            print((a1,a2),inp)
            err+=1
        case+=1
    print('Tested',case,'case with',err,'errors')
def GI(V,E,ls=None,Directed=False,index=1):
    org_inp=[];g=[[] for i in range(V)]
    FromStdin=True if ls==None else False
    for i in range(E):
        if FromStdin:
            inp=LI()
            org_inp.append(inp)
        else:
            inp=ls[i]
        if len(inp)==2:
            a,b=inp;c=1
        else:
            a,b,c=inp
        if index==1:a-=1;b-=1
        aa=(a,c);bb=(b,c);g[a].append(bb)
        if not Directed:g[b].append(aa)
    return g,org_inp
def GGI(h,w,search=None,replacement_of_found='.',mp_def={'#':1,'.':0},boundary=1):
    #h,w,g,sg=GGI(h,w,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0},boundary=1) # sample usage
    mp=[boundary]*(w+2);found={}
    for i in R(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[boundary]+[mp_def[j] for j in s]+[boundary]
    mp+=[boundary]*(w+2)
    return h+2,w+2,mp,found
def TI(n):return GI(n,n-1)
def accum(ls):
    rt=[0]
    for i in ls:rt+=[rt[-1]+i]
    return rt
def bit_combination(n,base=2):
    rt=[]
    for tb in R(base**n):s=[tb//(base**bt)%base for bt in R(n)];rt+=[s]
    return rt
def gcd(x,y):
    if y==0:return x
    if x%y==0:return y
    while x%y!=0:x,y=y,x%y
    return y
def YN(x):print(['NO','YES'][x])
def Yn(x):print(['No','Yes'][x])
def show(*inp,end='\n'):
    if show_flg:print(*inp,end=end)

mo=10**9+7
inf=float('inf')
FourNb=[(-1,0),(1,0),(0,1),(0,-1)];EightNb=[(-1,0),(1,0),(0,1),(0,-1),(1,1),(-1,-1),(1,-1),(-1,1)];compas=dict(zip('WENS',FourNb));cursol=dict(zip('LRUD',FourNb))
l_alp=string.ascii_lowercase
#sys.setrecursionlimit(10**9)
read=sys.stdin.buffer.read;readline=sys.stdin.buffer.readline;input=lambda:sys.stdin.readline().rstrip()


show_flg=False
show_flg=True

ans=0

h,w,k=LI()
v=[[0]*(w+1) for i in range(h+1)]
for i in rep(k):
    a,b,x=LI()
    v[a][b]=x

dp=[[[0]*(w+1) for i in range(h+1)] for i in range(4)]

for i in range(1,h+1):
    for j in range(1,w+1):
        up_max=max(dp[x][i-1][j]for x in range(4))
        dp[0][i][j]=up_max
        if v[i][j]!=0:
            dp[1][i][j]=max(dp[1][i][j],up_max+v[i][j])
        dp[0][i][j]=max(dp[0][i][j],dp[0][i][j-1])
        for x in range(1,4)[::-1]:
            dp[x][i][j]=max(dp[x][i][j],dp[x][i][j-1],dp[x-1][i][j-1]+v[i][j])
            

ans=max([dp[x][h][w]for x in range(4)])
print(ans) import sys,bisect,string,math,time,functools,random,fractions sys bisect string math time functools random fractions from heapq import heappush,heappop,heapify from collections import deque,defaultdict,Counter from itertools import permutations,combinations,groupby rep=range rep range R=range R range def Golf():n,*t=map(int,open(0).read().split()) Golf def I():return int(input()) I def S_():return input() S_ def IS():return input().split() IS i for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() i def LS():return [i for i in input().split()] LS def MI():return map(int,input().split()) MI int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i def LI():return [int(i) for i in input().split()] LI int(i)-1 for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i)-1 int(i) int i 1 def LI_():return [int(i)-1 for i in input().split()] LI_ int(input()) for i in range(n) for i in range(n) i range(n) range n for i in range(n) int(input()) int input() input def NI(n):return [int(input()) for i in range(n)] NI n n int(input())-1 for i in range(n) for i in range(n) i range(n) range n for i in range(n) int(input())-1 int(input()) int input() input 1 def NI_(n):return [int(input())-1 for i in range(n)] NI_ n n ord(i)-97 for i in input() for i in input() i input() input for i in input() ord(i)-97 ord(i) ord i 97 def StoLI():return [ord(i)-97 for i in input()] StoLI def ItoS(n):return chr(n+97) ItoS n n chr(i+97) for i in ls for i in ls i ls for i in ls chr(i+97) chr i+97 i 97 def LtoS(ls):return ''.join([chr(i+97) for i in ls]) LtoS ls ls def RA():return map(int,open(0).read().split()) RA random.randint(a,b)for i in range(n) for i in range(n) i range(n) range n for i in range(n) random.randint(a,b) random.randint random randint a b def RLI(n=8,a=1,b=10):return [random.randint(a,b)for i in range(n)] RLI n=8 n 8 a=1 a 1 b=10 b 10 def RI(a=1,b=10):return random.randint(a,b) RI a=1 a 1 b=10 b 10 def Rtest(T):
    case,err=0,0
    for i in range(T):
        inp=INP()
        a1,ls=naive(*inp)
        a2=solve(*inp)
        if a1!=a2:
            print((a1,a2),inp)
            err+=1
        case+=1
    print('Tested',case,'case with',err,'errors') Rtest case,err=0,0 case 0 err 0 for i in range(T):
        inp=INP()
        a1,ls=naive(*inp)
        a2=solve(*inp)
        if a1!=a2:
            print((a1,a2),inp)
            err+=1
        case+=1
     i range(T) range T inp=INP() inp INP() INP a1,ls=naive(*inp) a1 naive(*inp) naive *inp inp ls a2=solve(*inp) a2 solve(*inp) solve *inp inp if a1!=a2:
            print((a1,a2),inp)
            err+=1
         a1!=a2 a1 a2 print((a1,a2),inp) print (a1,a2) a1 a2 inp err+=1 err 1 case+=1 case 1 print('Tested',case,'case with',err,'errors') print 'Tested' case 'case with' err 'errors' T T def GI(V,E,ls=None,Directed=False,index=1):
    org_inp=[];g=[[] for i in range(V)]
    FromStdin=True if ls==None else False
    for i in range(E):
        if FromStdin:
            inp=LI()
            org_inp.append(inp)
        else:
            inp=ls[i]
        if len(inp)==2:
            a,b=inp;c=1
        else:
            a,b,c=inp
        if index==1:a-=1;b-=1
        aa=(a,c);bb=(b,c);g[a].append(bb)
        if not Directed:g[b].append(aa)
    return g,org_inp GI [] for i in range(V) for i in range(V) i range(V) range V for i in range(V) [] org_inp=[] org_inp [] g=[[] for i in range(V)] g [[] for i in range(V)] FromStdin=True if ls==None else False FromStdin True if ls==None else False ls==None ls None True False for i in range(E):
        if FromStdin:
            inp=LI()
            org_inp.append(inp)
        else:
            inp=ls[i]
        if len(inp)==2:
            a,b=inp;c=1
        else:
            a,b,c=inp
        if index==1:a-=1;b-=1
        aa=(a,c);bb=(b,c);g[a].append(bb)
        if not Directed:g[b].append(aa)
     i range(E) range E if FromStdin:
            inp=LI()
            org_inp.append(inp)
        else:
            inp=ls[i]
         FromStdin inp=LI() inp LI() LI org_inp.append(inp) org_inp.append org_inp append inp inp=ls[i] inp ls[i] ls i if len(inp)==2:
            a,b=inp;c=1
        else:
            a,b,c=inp
         len(inp)==2 len(inp) len inp 2 a,b=inp a inp b c=1 c 1 a,b,c=inp a inp b c if index==1:a-=1;b-=1
         index==1 index 1 aa=(a,c) aa (a,c) a c bb=(b,c) bb (b,c) b c g[a].append(bb) [a].append [a] g a append bb if not Directed:g[b].append(aa)
     not Directed Directed return g,org_inp return g,org_inp g org_inp V V E E ls=None ls None Directed=False Directed False index=1 index 1 def GGI(h,w,search=None,replacement_of_found='.',mp_def={'#':1,'.':0},boundary=1):
    #h,w,g,sg=GGI(h,w,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0},boundary=1) # sample usage
    mp=[boundary]*(w+2);found={}
    for i in R(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[boundary]+[mp_def[j] for j in s]+[boundary]
    mp+=[boundary]*(w+2)
    return h+2,w+2,mp,found GGI mp=[boundary]*(w+2) mp [boundary]*(w+2) [boundary] boundary w+2 w 2 found={} found {} for i in R(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[boundary]+[mp_def[j] for j in s]+[boundary]
     i R(h) R h s=input() s input() input for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
         char search if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
         char in s char s found[char]=((i+1)*(w+2)+s.index(char)+1) found[char] found char (i+1)*(w+2)+s.index(char)+1 (i+1)*(w+2)+s.index(char) (i+1)*(w+2) i+1 i 1 w+2 w 2 s.index(char) s.index s index char 1 mp_def[char]=mp_def[replacement_of_found] mp_def[char] mp_def char mp_def[replacement_of_found] mp_def replacement_of_found mp_def[j] for j in s for j in s j s for j in s mp_def[j] mp_def j mp+=[boundary]+[mp_def[j] for j in s]+[boundary] mp [boundary]+[mp_def[j] for j in s]+[boundary] [boundary]+[mp_def[j] for j in s] [boundary] boundary [mp_def[j] for j in s] [boundary] boundary mp+=[boundary]*(w+2) mp [boundary]*(w+2) [boundary] boundary w+2 w 2 return h+2,w+2,mp,found return h+2,w+2,mp,found h+2 h 2 w+2 w 2 mp found h h w w search=None search None replacement_of_found='.' replacement_of_found '.' mp_def={'#':1,'.':0} mp_def {'#':1,'.':0} '#' '#' 1 '.' '.' 0 boundary=1 boundary 1 def TI(n):return GI(n,n-1) TI n n def accum(ls):
    rt=[0]
    for i in ls:rt+=[rt[-1]+i]
    return rt accum rt=[0] rt [0] 0 for i in ls:rt+=[rt[-1]+i]
     i ls return rt rt ls ls def bit_combination(n,base=2):
    rt=[]
    for tb in R(base**n):s=[tb//(base**bt)%base for bt in R(n)];rt+=[s]
    return rt bit_combination rt=[] rt [] tb//(base**bt)%base for bt in R(n) for bt in R(n) bt R(n) R n for bt in R(n) tb//(base**bt)%base tb//(base**bt) tb base**bt base bt base for tb in R(base**n):s=[tb//(base**bt)%base for bt in R(n)];rt+=[s]
     tb R(base**n) R base**n base n return rt rt n n base=2 base 2 def gcd(x,y):
    if y==0:return x
    if x%y==0:return y
    while x%y!=0:x,y=y,x%y
    return y gcd if y==0:return x
     y==0 y 0 if x%y==0:return y
     x%y==0 x%y x y 0 while x%y!=0:x,y=y,x%y
     x%y!=0 x%y x y 0 return y y x x y y def YN(x):print(['NO','YES'][x]) YN x x def Yn(x):print(['No','Yes'][x]) Yn x x def show(*inp,end='\n'):
    if show_flg:print(*inp,end=end) show if show_flg:print(*inp,end= show_flg end='\n' end '\n' *inp mo=10**9+7 mo 10**9+7 10**9 10 9 7 inf=float('inf') inf float('inf') float 'inf' FourNb=[(-1,0),(1,0),(0,1),(0,-1)] FourNb [(-1,0),(1,0),(0,1),(0,-1)] (-1,0) -1 0 (1,0) 1 0 (0,1) 0 1 (0,-1) 0 -1 EightNb=[(-1,0),(1,0),(0,1),(0,-1),(1,1),(-1,-1),(1,-1),(-1,1)] EightNb [(-1,0),(1,0),(0,1),(0,-1),(1,1),(-1,-1),(1,-1),(-1,1)] (-1,0) -1 0 (1,0) 1 0 (0,1) 0 1 (0,-1) 0 -1 (1,1) 1 1 (-1,-1) -1 -1 (1,-1) 1 -1 (-1,1) -1 1 compas=dict(zip('WENS',FourNb)) compas dict(zip('WENS',FourNb)) dict zip('WENS',FourNb) zip 'WENS' FourNb cursol=dict(zip('LRUD',FourNb)) cursol dict(zip('LRUD',FourNb)) dict zip('LRUD',FourNb) zip 'LRUD' FourNb l_alp=string.ascii_lowercase l_alp string.ascii_lowercase string ascii_lowercase read=sys.stdin.buffer.read read sys.stdin.buffer.read sys.stdin.buffer sys.stdin sys stdin buffer read readline=sys.stdin.buffer.readline readline sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline input=lambda:sys.stdin.readline().rstrip() input lambda:sys.stdin.readline().rstrip() sys.stdin.readline().rstrip() sys.stdin.readline().rstrip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline rstrip show_flg=False show_flg False show_flg=True show_flg True ans=0 ans 0 h,w,k=LI() h LI() LI w k [0]*(w+1) for i in range(h+1) for i in range(h+1) i range(h+1) range h+1 h 1 for i in range(h+1) [0]*(w+1) [0] 0 w+1 w 1 v=[[0]*(w+1) for i in range(h+1)] v [[0]*(w+1) for i in range(h+1)] for i in rep(k):
    a,b,x=LI()
    v[a][b]=x i rep(k) rep k a,b,x=LI() a LI() LI b x v[a][b]=x v[a][b] [a] v a b x [[0]*(w+1) for i in range(h+1)] for i in range(4) for i in range(4) i range(4) range 4 for i in range(4) [[0]*(w+1) for i in range(h+1)] dp=[[[0]*(w+1) for i in range(h+1)] for i in range(4)] dp [[[0]*(w+1) for i in range(h+1)] for i in range(4)] for i in range(1,h+1):
    for j in range(1,w+1):
        up_max=max(dp[x][i-1][j]for x in range(4))
        dp[0][i][j]=up_max
        if v[i][j]!=0:
            dp[1][i][j]=max(dp[1][i][j],up_max+v[i][j])
        dp[0][i][j]=max(dp[0][i][j],dp[0][i][j-1])
        for x in range(1,4)[::-1]:
            dp[x][i][j]=max(dp[x][i][j],dp[x][i][j-1],dp[x-1][i][j-1]+v[i][j])
             i range(1,h+1) range 1 h+1 h 1 for j in range(1,w+1):
        up_max=max(dp[x][i-1][j]for x in range(4))
        dp[0][i][j]=up_max
        if v[i][j]!=0:
            dp[1][i][j]=max(dp[1][i][j],up_max+v[i][j])
        dp[0][i][j]=max(dp[0][i][j],dp[0][i][j-1])
        for x in range(1,4)[::-1]:
            dp[x][i][j]=max(dp[x][i][j],dp[x][i][j-1],dp[x-1][i][j-1]+v[i][j])
             j range(1,w+1) range 1 w+1 w 1 up_max=max(dp[x][i-1][j]for x in range(4)) up_max max(dp[x][i-1][j]for x in range(4)) max dp[x][i-1][j] [i-1] [x] dp x i-1 i 1 j dp[0][i][j]=up_max dp[0][i][j] [i] [0] dp 0 i j up_max if v[i][j]!=0:
            dp[1][i][j]=max(dp[1][i][j],up_max+v[i][j])
         v[i][j]!=0 v[i][j] [i] v i j 0 dp[1][i][j]=max(dp[1][i][j],up_max+v[i][j]) dp[1][i][j] [i] [1] dp 1 i j max(dp[1][i][j],up_max+v[i][j]) max dp[1][i][j] [i] [1] dp 1 i j up_max+v[i][j] up_max v[i][j] [i] v i j dp[0][i][j]=max(dp[0][i][j],dp[0][i][j-1]) dp[0][i][j] [i] [0] dp 0 i j max(dp[0][i][j],dp[0][i][j-1]) max dp[0][i][j] [i] [0] dp 0 i j dp[0][i][j-1] [i] [0] dp 0 i j-1 j 1 for x in range(1,4)[::-1]:
            dp[x][i][j]=max(dp[x][i][j],dp[x][i][j-1],dp[x-1][i][j-1]+v[i][j])
             x range(1,4)[::-1] (1,4) range 1 4 ::-1 -1 dp[x][i][j]=max(dp[x][i][j],dp[x][i][j-1],dp[x-1][i][j-1]+v[i][j]) dp[x][i][j] [i] [x] dp x i j max(dp[x][i][j],dp[x][i][j-1],dp[x-1][i][j-1]+v[i][j]) max dp[x][i][j] [i] [x] dp x i j dp[x][i][j-1] [i] [x] dp x i j-1 j 1 dp[x-1][i][j-1]+v[i][j] dp[x-1][i][j-1] [i] [x-1] dp x-1 x 1 i j-1 j 1 v[i][j] [i] v i j dp[x][h][w]for x in range(4) for x in range(4) x range(4) range 4 for x in range(4) dp[x][h][w] [h] [x] dp x h w ans=max([dp[x][h][w]for x in range(4)]) ans max([dp[x][h][w]for x in range(4)]) max [dp[x][h][w]for x in range(4)] print(ans) print ans def GI(V,E,ls=None,Directed=False,index=1):
    org_inp=[];g=[[] for i in range(V)]
    FromStdin=True if ls==None else False
    for i in range(E):
        if FromStdin:
            inp=LI()
            org_inp.append(inp)
        else:
            inp=ls[i]
        if len(inp)==2:
            a,b=inp;c=1
        else:
            a,b,c=inp
        if index==1:a-=1;b-=1
        aa=(a,c);bb=(b,c);g[a].append(bb)
        if not Directed:g[b].append(aa)
    return g,org_inp def GI(V,E,ls=None,Directed=False,index=1):
    org_inp=[];g=[[] for i in range(V)]
    FromStdin=True if ls==None else False
    for i in range(E):
        if FromStdin:
            inp=LI()
            org_inp.append(inp)
        else:
            inp=ls[i]
        if len(inp)==2:
            a,b=inp;c=1
        else:
            a,b,c=inp
        if index==1:a-=1;b-=1
        aa=(a,c);bb=(b,c);g[a].append(bb)
        if not Directed:g[b].append(aa)
    return g,org_inp GI def YN(x):print(['NO','YES'][x]) def YN(x):print(['NO','YES'][x]) YN def NI_(n):return [int(input())-1 for i in range(n)] def NI_(n):return [int(input())-1 for i in range(n)] NI_ up_max=max(dp[x][i-1][j]for x in range(4)) max(dp[x][i-1][j]for x in range(4)) up_max ans=0 0 ans v=[[0]*(w+1) for i in range(h+1)] [[0]*(w+1) for i in range(h+1)] v h,w,k=LI() LI() h R=range range R input=lambda:sys.stdin.readline().rstrip() lambda:sys.stdin.readline().rstrip() input k=LI() LI() k def ItoS(n):return chr(n+97) def ItoS(n):return chr(n+97) ItoS def Golf():n,*t=map(int,open(0).read().split()) def Golf():n,*t=map(int,open(0).read().split()) Golf def GGI(h,w,search=None,replacement_of_found='.',mp_def={'#':1,'.':0},boundary=1):
    #h,w,g,sg=GGI(h,w,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0},boundary=1) # sample usage
    mp=[boundary]*(w+2);found={}
    for i in R(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[boundary]+[mp_def[j] for j in s]+[boundary]
    mp+=[boundary]*(w+2)
    return h+2,w+2,mp,found def GGI(h,w,search=None,replacement_of_found='.',mp_def={'#':1,'.':0},boundary=1):
    #h,w,g,sg=GGI(h,w,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0},boundary=1) # sample usage
    mp=[boundary]*(w+2);found={}
    for i in R(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[boundary]+[mp_def[j] for j in s]+[boundary]
    mp+=[boundary]*(w+2)
    return h+2,w+2,mp,found GGI def RI(a=1,b=10):return random.randint(a,b) def RI(a=1,b=10):return random.randint(a,b) RI readline=sys.stdin.buffer.readline sys.stdin.buffer.readline readline read=sys.stdin.buffer.read sys.stdin.buffer.read read b,x=LI() LI() b w,k=LI() LI() w inf=float('inf') float('inf') inf def accum(ls):
    rt=[0]
    for i in ls:rt+=[rt[-1]+i]
    return rt def accum(ls):
    rt=[0]
    for i in ls:rt+=[rt[-1]+i]
    return rt accum a,b,x=LI() LI() a def LI_():return [int(i)-1 for i in input().split()] def LI_():return [int(i)-1 for i in input().split()] LI_ def TI(n):return GI(n,n-1) def TI(n):return GI(n,n-1) TI def S_():return input() def S_():return input() S_ show_flg=False False show_flg def IS():return input().split() def IS():return input().split() IS def Yn(x):print(['No','Yes'][x]) def Yn(x):print(['No','Yes'][x]) Yn def RA():return map(int,open(0).read().split()) def RA():return map(int,open(0).read().split()) RA def LI():return [int(i) for i in input().split()] def LI():return [int(i) for i in input().split()] LI def RLI(n=8,a=1,b=10):return [random.randint(a,b)for i in range(n)] def RLI(n=8,a=1,b=10):return [random.randint(a,b)for i in range(n)] RLI EightNb=[(-1,0),(1,0),(0,1),(0,-1),(1,1),(-1,-1),(1,-1),(-1,1)] [(-1,0),(1,0),(0,1),(0,-1),(1,1),(-1,-1),(1,-1),(-1,1)] EightNb FourNb=[(-1,0),(1,0),(0,1),(0,-1)] [(-1,0),(1,0),(0,1),(0,-1)] FourNb mo=10**9+7 10**9+7 mo show_flg=True True show_flg def LtoS(ls):return ''.join([chr(i+97) for i in ls]) def LtoS(ls):return ''.join([chr(i+97) for i in ls]) LtoS def MI():return map(int,input().split()) def MI():return map(int,input().split()) MI dp=[[[0]*(w+1) for i in range(h+1)] for i in range(4)] [[[0]*(w+1) for i in range(h+1)] for i in range(4)] dp def bit_combination(n,base=2):
    rt=[]
    for tb in R(base**n):s=[tb//(base**bt)%base for bt in R(n)];rt+=[s]
    return rt def bit_combination(n,base=2):
    rt=[]
    for tb in R(base**n):s=[tb//(base**bt)%base for bt in R(n)];rt+=[s]
    return rt bit_combination def show(*inp,end='\n'):
    if show_flg:print(*inp,end=end) def show(*inp,end='\n'):
    if show_flg:print(*inp,end=end) show def Rtest(T):
    case,err=0,0
    for i in range(T):
        inp=INP()
        a1,ls=naive(*inp)
        a2=solve(*inp)
        if a1!=a2:
            print((a1,a2),inp)
            err+=1
        case+=1
    print('Tested',case,'case with',err,'errors') def Rtest(T):
    case,err=0,0
    for i in range(T):
        inp=INP()
        a1,ls=naive(*inp)
        a2=solve(*inp)
        if a1!=a2:
            print((a1,a2),inp)
            err+=1
        case+=1
    print('Tested',case,'case with',err,'errors') Rtest def gcd(x,y):
    if y==0:return x
    if x%y==0:return y
    while x%y!=0:x,y=y,x%y
    return y def gcd(x,y):
    if y==0:return x
    if x%y==0:return y
    while x%y!=0:x,y=y,x%y
    return y gcd compas=dict(zip('WENS',FourNb)) dict(zip('WENS',FourNb)) compas def LS():return [i for i in input().split()] def LS():return [i for i in input().split()] LS x=LI() LI() x def NI(n):return [int(input()) for i in range(n)] def NI(n):return [int(input()) for i in range(n)] NI def I():return int(input()) def I():return int(input()) I cursol=dict(zip('LRUD',FourNb)) dict(zip('LRUD',FourNb)) cursol ans=max([dp[x][h][w]for x in range(4)]) max([dp[x][h][w]for x in range(4)]) ans rep=range range rep def StoLI():return [ord(i)-97 for i in input()] def StoLI():return [ord(i)-97 for i in input()] StoLI l_alp=string.ascii_lowercase string.ascii_lowercase l_alp
import sys,bisect,string,math,time,functools,random,fractions
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations,groupby
rep=range;R=range
def Golf():n,*t=map(int,open(0).read().split())
def I():return int(input())
def S_():return input()
def IS():return input().split()
def LS():return [i for i in input().split()]
def MI():return map(int,input().split())
def LI():return [int(i) for i in input().split()]
def LI_():return [int(i)-1 for i in input().split()]
def NI(n):return [int(input()) for i in range(n)]
def NI_(n):return [int(input())-1 for i in range(n)]
def StoLI():return [ord(i)-97 for i in input()]
def ItoS(n):return chr(n+97)
def LtoS(ls):return ''.join([chr(i+97) for i in ls])
def RA():return map(int,open(0).read().split())
def RLI(n=8,a=1,b=10):return [random.randint(a,b)for i in range(n)]
def RI(a=1,b=10):return random.randint(a,b)
def Rtest(T):
    case,err=0,0
    for i in range(T):
        inp=INP()
        a1,ls=naive(*inp)
        a2=solve(*inp)
        if a1!=a2:
            print((a1,a2),inp)
            err+=1
        case+=1
    print('Tested',case,'case with',err,'errors')
def GI(V,E,ls=None,Directed=False,index=1):
    org_inp=[];g=[[] for i in range(V)]
    FromStdin=True if ls==None else False
    for i in range(E):
        if FromStdin:
            inp=LI()
            org_inp.append(inp)
        else:
            inp=ls[i]
        if len(inp)==2:
            a,b=inp;c=1
        else:
            a,b,c=inp
        if index==1:a-=1;b-=1
        aa=(a,c);bb=(b,c);g[a].append(bb)
        if not Directed:g[b].append(aa)
    return g,org_inp
def GGI(h,w,search=None,replacement_of_found='.',mp_def={'#':1,'.':0},boundary=1):
    #h,w,g,sg=GGI(h,w,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0},boundary=1) # sample usage
    mp=[boundary]*(w+2);found={}
    for i in R(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[boundary]+[mp_def[j] for j in s]+[boundary]
    mp+=[boundary]*(w+2)
    return h+2,w+2,mp,found
def TI(n):return GI(n,n-1)
def accum(ls):
    rt=[0]
    for i in ls:rt+=[rt[-1]+i]
    return rt
def bit_combination(n,base=2):
    rt=[]
    for tb in R(base**n):s=[tb//(base**bt)%base for bt in R(n)];rt+=[s]
    return rt
def gcd(x,y):
    if y==0:return x
    if x%y==0:return y
    while x%y!=0:x,y=y,x%y
    return y
def YN(x):print(['NO','YES'][x])
def Yn(x):print(['No','Yes'][x])
def show(*inp,end='\n'):
    if show_flg:print(*inp,end=end)

mo=10**9+7
inf=float('inf')
FourNb=[(-1,0),(1,0),(0,1),(0,-1)];EightNb=[(-1,0),(1,0),(0,1),(0,-1),(1,1),(-1,-1),(1,-1),(-1,1)];compas=dict(zip('WENS',FourNb));cursol=dict(zip('LRUD',FourNb))
l_alp=string.ascii_lowercase
#sys.setrecursionlimit(10**9)
read=sys.stdin.buffer.read;readline=sys.stdin.buffer.readline;input=lambda:sys.stdin.readline().rstrip()


show_flg=False
show_flg=True

ans=0

h,w,k=LI()
v=[[0]*(w+1) for i in range(h+1)]
for i in rep(k):
    a,b,x=LI()
    v[a][b]=x

dp=[[[0]*(w+1) for i in range(h+1)] for i in range(4)]

for i in range(1,h+1):
    for j in range(1,w+1):
        up_max=max(dp[x][i-1][j]for x in range(4))
        dp[0][i][j]=up_max
        if v[i][j]!=0:
            dp[1][i][j]=max(dp[1][i][j],up_max+v[i][j])
        dp[0][i][j]=max(dp[0][i][j],dp[0][i][j-1])
        for x in range(1,4)[::-1]:
            dp[x][i][j]=max(dp[x][i][j],dp[x][i][j-1],dp[x-1][i][j-1]+v[i][j])
            

ans=max([dp[x][h][w]for x in range(4)])
print(ans)
