R,C,K = gets.chomp.split(" ").map(&:to_i)
r,c,v = K.times.map{gets.split.map(&:to_i)}.transpose
value = Array.new(R+1){Array.new(C+1,0)}
K.times do |i|
  value[r[i]-1][c[i]-1] = v[i]
end
dp = Array.new(R){Array.new(C){Array.new(4,0)}}
dp[0][0][0] = 0
dp[0][0][1] = value[0][0]
R.times do |i|
  C.times do |j|
    dp[i][j] = 1
  end
end
puts dp[R-1][C-1][0..3].max