#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン!!!!
#define int long long
#define str string
#define rep(i,j) for(int i=0;i<(int)(j);i++)
typedef long long ll;
typedef long double ld;
const ll inf = 4523372036854775807;
short gh[2][4] = { { 0,0,-1,1 },{ -1,1,0,0 } };
struct P {
ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
ll to, cost;
};
struct S {//辺の情報を入れる変数
int from, to, cost;
};
struct H {
int x, y;
};
bool operator<(H a, H b) {
if (a.x != b.x) return a.x < b.x;
return a.y < b.y;
}
ll gcm(ll i, ll j) {//最大公約数
if (i > j) swap(i, j);
if (i == 0) return j;
return gcm(j%i, i);
}
ld rad(ld a, ld b, ld c, ld d) {
return sqrt(pow(a - c, 2) + pow(b - d, 2));
}//rad=座標上の2点間の距離
int ari(int a, int b, int c) {
return (a + b)*c / 2;
}//等差数列の和
bool suf(ld a, ld b, ld c, ld d) {
if (b <= c || d <= a) return 0;
return 1;
}//[a,b),[c,d)
//距離を[a]、辺を[e]とするダイクストラ
/*void dijk(int n,int s) {//頂点の数、出発点
priority_queue<P, vector<P>, greater<P>>p;
for (int i = 1; i <= n; i++)
a[i] = inf;
a[s] = 0;
p.push(P{ s,0 });
while (!p.empty()) {
P t = p.top(); p.pop();
for (int i = 0; i < e[t.pos].size(); i++) {
if (a[e[t.pos][i].to] > a[t.pos] + e[t.pos][i].to) {
a[e[t.pos][i].to] = a[t.pos] + e[t.pos][i].cost;
p.push(P{ e[t.pos][i].to,a[e[t.pos][i].to] });
}
}
}
}*/
int dat[200000];
int query(int i, int a, int b, int l, int r) {
if (b <= l || a >= r) return inf;
if (a <= l&&r <= b) return dat[i];
int res = query(i * 2 + 1, a, b, l, (l + r) / 2);
res = min(res, query(i * 2 + 2, a, b, (l + r) / 2, r));
return res;
}
void update(int i, int s,int n) {//変える場所、変える値、要素数
i = n + i - 1;
dat[i] = s;
while (i > 0) {
i = (i - 1) / 2;
dat[i] = min(dat[i * 2 + 1], dat[i * 2 + 2]);
}
}
//---------------------------------------------------
//+++++++++++++++++++++++++++++++++++++++++++++++++++
int n, x, y;
int t[300], h[300], dp[301][301][601];
signed main() {
cin >> x >> y >> n;
for (int i = 0; i < n; i++)
cin >> t[i] >> h[i];
for (int i = 0; i < n; i++)
for (int j = 0; j <= x; j++)
for (int z = 0; z <= x+y; z++)
dp[i][j][z] = -1;
dp[0][0][0] = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < x; j++) {
for (int z = 0; z <= x+y; z++) {
if (dp[i][j][z] == -1) continue;
dp[i + 1][j][z] = max(dp[i + 1][j][z], dp[i][j][z]);
if (z + t[i] > x + y) continue;
dp[i + 1][j + 1][z + t[i]] = max(dp[i + 1][j + 1][z + t[i]], dp[i][j][z] + h[i]);
}
}
}
int sum = 0;
for (int i = 0; i <= n; i++)
for (int j = 0; j <= x; j++)
for (int z = 0; z <= x+y; z++)
sum = max(sum, dp[i][j][z]);
cout << sum << endl;
getchar(); getchar();
}