r,c,k = gets.split(' ')
r = r.to_i
c = c.to_i
k = k.to_i
hash = Hash.new
k.times do |i|
    x,y,v = gets.split(' ')
    x = (x.to_i) -1
    y = (y.to_i) -1
    hash[x*c+y] = v.to_i
end
nxt = dp = Array.new(c+1){Array.new(4,0)}

# for x in 0...r do
#     for y in 0...c do
#         for cnt in 0..3 do
#             now = dp[y][cnt]
#             nxt[y][0] = now if nxt[y][0] < now
#             dp[y+1][cnt] = now if dp[y+1][cnt] < now
#             sc = hash.fetch(x*c+y,0)
            
#             if sc>0 and cnt<=2 then
#                 nxt[y][0] = now + sc if nxt[y][0] < now +sc
#                 dp[y+1][cnt+1] = now + sc if dp[y+1][cnt+1] < now + sc
#             end
#             #puts "#{x} #{y} #{cnt} #{dp[x][y][cnt]}"
#         end
#     end
#     dp,nxt = nxt,dp
# end

puts dp[c-1].max
