let () =
    let rdint =
        let l = ref 0 in
        let i = ref 0 in
        let s = Bytes.create 1048576 in
        let refill () =
            let n = input stdin s 0 1048576 in
            i := 0;
            l := n
        in

        fun () ->
            let rec loop2 j k t =
                let fin j t =
                    i := j;
                    t
                in

                if j = k then (
                    refill ();
                    if !l > 0 then loop2 !i !l t else fin j t
                ) else if Bytes.get s j >= '0' && Bytes.get s j <= '9' then
                    loop2 (j + 1) k (t * 10 + int_of_char (Bytes.get s j) - 48)
                else fin j t
            in
            let rec loop1 j k =
                if j = k then (
                    refill ();
                    if !l > 0 then loop1 !i !l else 0
                ) else
                if Bytes.get s j >= '0' && Bytes.get s j <= '9' then loop2 (j + 1) k (int_of_char (Bytes.get s j) - 48) else
                    loop1 (j + 1) k
            in
            loop1 !i !l
    in
    let main () =
        let rr = rdint() in
        let cc = rdint() in
        let k = rdint() in
        let mat = Array.make_matrix rr cc 0 in
        for i = 1 to k do
            let r = rdint () - 1 in
            let c = rdint () - 1 in
            let v = rdint () in
            mat.(r).(c) <- v
        done;
        let max (a:int) (b:int) = if a < b then b else a in

        let prev = Array.make cc 0 in
        for y = 0 to rr - 1 do
            let m = mat.(y) in
            let rec loop x work0 work1 work2 work3 =
                if x < cc then (
                    let work0 = max work0 prev.(x) in
                    let v = m.(x) in
                    let work3 = max work3 (work2 + v) in
                    let work2 = max work2 (work1 + v) in
                    let work1 = max work1 (work0 + v) in
                    prev.(x) <- max (max work3 work2) (max work1 work0);
                    loop (x + 1) work0 work1 work2 work3
                )
            in
            loop 0 0 0 0 0
        done;
        Printf.printf "%d\n" (prev.(cc - 1))
    in
    main ()