#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int f[125][125];
int wo[1002];
int wn[1002];
int w[1002];
int O2,N2;
int n;
int min(int x,int y)
{
if(x<y)return x;
return y;
}
int main()
{
freopen("ple.in","r",stdin);
freopen("ple.out","w",stdout);
scanf("%d%d",&O2,&N2);
scanf("%d",&n);
int i,j,k;
for(i=1;i<=n;i++)
scanf("%d%d%d",&wo[i],&wn[i],&w[i]);
memset(f,127,sizeof(f));
f[0][0]=0;
for(i=1;i<=n;i++)
for(j=O2;j>=0;j--)
for(k=N2;k>=0;k--)
{
int J=j+wo[i];
int K=k+wn[i];
if(J>O2)J=O2;
if(K>N2)K=N2;
f[J][K]=min(f[J][K],f[j][k]+w[i]);
}
printf("%d",f[O2][N2]);
return 0;
}