var t0, a0, n, t1, a1, i, j, k : longint;
t, a, w : array [1..1000] of longint;
st : array [0..21, 0..79] of longint;
begin
assign(input,'ple.in');reset(input);
assign(output,'ple.out');rewrite(output);
readln(t0,a0);
readln(n);
for i := 1 to n do
readln(t[i], a[i], w[i]);
fillchar(st, sizeof(st), $7F); st[0][0] := 0;
for k := 1 to n do
for i := t0 downto 0 do
for j := a0 downto 0 do
begin
t1 := i + t[k]; if t1 > t0 then t1 := t0;
a1 := j + a[k]; if a1 > a0 then a1 := a0;
if st[i][j] + w[k] < st[t1][a1]
then st[t1][a1] := st[i][j] + w[k]
end;
writeln(st[t0][a0]);
close(input);
close(output);
end.