# Studying https://atcoder.jp/contests/abc175/submissions/16084621

(R,C,K),*RCV = $<.map{|ln| ln.split.map(&:to_i) }

Rs = Array.new(R){ [] }
RCV.each{|s,d,v|
	Rs[s-1] << [d-1,v]
}

r0 = [0]*C
while r = Rs.shift
	r.empty? and next or r.sort!

	vs = [0]*4
	until r.empty?
		c,v = r.shift
		vs[0] = r0[c]
		vs[3] = vs[2]+v if vs[3] < vs[2]+v
		vs[2] = vs[1]+v if vs[2] < vs[1]+v
		vs[1] = vs[0]+v if vs[1] < vs[0]+v
		r0[c] = vs.max
	end

	c = 0
	r0[c] = r0[c-1] if r0[c] < r0[c-1] while C > c+=1
end

p r0[-1]
