#include using namespace std; using ll = long long; int main(){ cin.tie(nullptr); ios_base::sync_with_stdio(false); ll N, P, K, T, B, inf=1e18+1; cin >> N >> P >> K; vector dp(N+1, vector(K+1)); dp[0][0] = P; for (int i=1; i<=N; i++){ cin >> T >> B; for (int j=0; j<=K; j++){ dp[i][j] = min(inf, max(dp[i][j], dp[i-1][j])); if (T == 1){ if (j>=1) dp[i][j] = min(inf, max(dp[i][j], dp[i-1][j-1]+B)); } else{ if (j>=1) dp[i][j] = min(inf, max(dp[i][j], dp[i-1][j-1]*2)); } } } if (dp[N][K] == inf) cout << -1 << endl; else cout << dp[N][K] << endl; return 0; }