#include <bits/stdc++.h>
using namespace std;
int dp[60][60][10001];
int main() {
  int W;
  int N, K;
  cin >> W;
  cin >> N >> K;
  vector<int> a(N);
  vector<int> b(N);
  for (int i = 0; i < (N); ++i) cin >> a[i] >> b[i];
  dp[0][0][0] = 0;
  for (int n = 0; n < (N + 1); ++n)
    for (int k = 0; k < (K + 1); ++k)
      for (int w = 0; w < (W + 1); ++w) {
        if (w - a[n] >= 0)
          dp[n + 1][k + 1][w] =
              max(dp[n + 1][k + 1][w], dp[n][k][w - a[n]] + b[n]);
        (dp[n][k + 1][w] = max(dp[n][k + 1][w], dp[n][k][w]));
      }
  cout << dp[N][K][W] << endl;
  return 0;
}
