N,P,K=map(int,input().split()) dp=[[0 for i in range(K+1)] for j in range(N+1)] dp[0][0]=P for i in range(1, N+1): T,B=map(int,input().split()) if T==1: for j in range(K+1): dp[i][j]=max(dp[i][j], dp[i-1][j], (dp[i-1][j-1]+B if j-1>=0 else 0)) if dp[i][j]>10**18: print(-1); exit() else: for j in range(K+1): dp[i][j]=max(dp[i][j], dp[i-1][j], 2*dp[i-1][j-1]) if dp[i][j]>10**18: print(-1); exit() dp[i][j]=max(dp[i][j], dp[i-1][j]) print(dp[N][K])