//object E {
object Main {
  import InOut._
  def main(args: Array[String]): Unit = {

    val r, c, k = nextInt
    val grid = Array.fill(r, c)(0)
    for (_ <- 1 to k) {
      val r, c, v = nextInt
      grid(r - 1)(c - 1) = v
    }
//grid.foreach(gg => println(gg.mkString(" ")))
    val hor, ver = Array.fill(3, r, c)(0L)

    var i = 0
    while (i < r) {
      var j = 0
      while (j < c) {
        val v = grid(i)(j)
        if (i > 0) {
          val vv0 = if (j > 0) ver(0)(i - 1)(j - 1) max ver(1)(i - 1)(j - 1) max ver(2)(i - 1)(j - 1) else 0
          val vv1 = ver(0)(i - 1)(j) max ver(1)(i - 1)(j) max ver(2)(i - 1)(j)
          hor(0)(i)(j) = Math.max(vv0 + v, hor(0)(i - 1)(j))
          hor(1)(i)(j) = Math.max(hor(0)(i - 1)(j) + v, hor(1)(i - 1)(j)) max vv1 + v
          hor(2)(i)(j) = Math.max(hor(1)(i - 1)(j) + v, hor(2)(i - 1)(j))
        } else {
          hor(0)(i)(j) = v
          hor(1)(i)(j) = v
          hor(2)(i)(j) = v
        }
        if (j > 0) {
          val hh0 = if (i > 0) hor(0)(i - 1)(j - 1) max hor(1)(i - 1)(j - 1) max hor(2)(i - 1)(j - 1) else 0
          val hh1 = hor(0)(i)(j - 1) max hor(1)(i)(j - 1) max hor(2)(i)(j - 1)
          ver(0)(i)(j) = Math.max(hh0 + v, ver(0)(i)(j - 1))
          ver(1)(i)(j) = Math.max(ver(0)(i)(j - 1) + v, ver(1)(i)(j - 1)) max hh1 + v
          ver(2)(i)(j) = Math.max(ver(1)(i)(j - 1) + v, ver(2)(i)(j - 1))
        } else {
          ver(0)(i)(j) = v
          ver(1)(i)(j) = v
          ver(2)(i)(j) = v
        }
        j += 1
      }
      i += 1
    }
//println((0 until 3).map(hor(_)(1)(3)).mkString(" "))
//    println((0 until 3).map(ver(_)(1)(3)).mkString(" "))
    val res = (0 until 3).map(m => hor(m)(r - 1)(c - 1) max ver(m)(r - 1)(c - 1)).max
    out.println(res)

    out.flush()
  }
 
  final object InOut {
    val in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))
    val out = new java.io.PrintWriter(System.out, false)
    private[this] var tokenizer: java.util.StringTokenizer = _
    def nextToken: String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new java.util.StringTokenizer(in.readLine)
      tokenizer.nextToken
    }
    def nextInt = Integer.parseInt(nextToken)
    def nextLong = java.lang.Long.parseLong(nextToken)
    def nextBig = BigInt(nextToken)
    def nextInts(n: Int) = Array.fill(n) { nextInt }
    def nextLongs(n: Int) = Array.fill(n) { nextLong }
    def nextBigs(n: Int) = Array.fill(n) { nextBig }
    def nextLine = in.readLine
  }
}
