#define rep(i,n) for(int i=0;i<(int)(n);i++) #define ALL(v) v.begin(),v.end() typedef long long ll; #include using namespace std; const ll INF=1000000000000000001; ll dp[1010][1010]; int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); ll n,p,k; cin>>n>>p>>k; vector T(n),B(n); rep(i,n) cin>>T[i]>>B[i]; dp[0][k]=p; rep(i,n){ rep(j,k+1){ dp[i+1][j]=max(dp[i+1][j],dp[i][j]); if(dp[i][j]==INF) continue; if(j==0) continue; if(T[i]==1) dp[i+1][j-1]=max(dp[i+1][j-1],dp[i][j]+B[i]); else dp[i+1][j-1]=max(dp[i+1][j-1],dp[i][j]*2); if(dp[i+1][j-1]>=INF) dp[i+1][j-1]=INF; } } if(dp[n][0]==INF) cout<<-1<