#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,m,n) for(int i=m; i<int(n); ++i)
#define repll(i,m,n) for(ll i=m; i<ll(n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define fi first
#define se second

template<typename T> bool chmin(T& a, T b){ if(a > b){a = b; return true;} return false; }
template<typename T> bool chmax(T& a, T b){ if(a < b){a = b; return true;} return false; }

template<typename T> T gcd(T a, T b){ return a % b ? gcd(b, a % b) : b; }
template<typename T> T lcm(T a, T b){ return a / gcd(a, b) * b; }

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N, K;
    ll P;
    cin >> N >> P >> K;

    vector<int> T(N);
    vector<ll> B(N);
    rep(i, 0, N) cin >> T[i] >> B[i];

    vector dp(N+1, vector<ll>(K+1, -1LL));
    dp[0][0] = P;
    const ll inf = 1000000000000000000LL;

    rep(i, 0, N){
        rep(j, 0, K+1){
            if(dp[i][j] == -1LL) continue;
            if(j != K){
                if(T[i] == 1){
                    if(inf > dp[i][j] + B[i]) chmax(dp[i+1][j+1], dp[i][j] + B[i]);
                    else chmax(dp[i+1][j+1], inf);
                }else{
                    if(inf / 2LL > dp[i][j]) chmax(dp[i+1][j+1], 2LL * dp[i][j]);
                    else chmax(dp[i+1][j+1], inf);
                }
            }
            chmax(dp[i+1][j], dp[i][j]);
        }
    }
    cout << (dp[N][K] == inf ? -1 : dp[N][K]) << endl;

    return 0;
}