n,p,k=map(int,input().split()) dp=[[0 for _ in range(k+1)]for _ in range(n+1)] dp[0][0]=p for i in range(1,n+1): s,t=map(int,input().split()) dp[i][0]=dp[i-1][0] for j in range(1,k+1): if s==1: dp[i][j]=max(dp[i-1][j],dp[i-1][j-1]+t) else: dp[i][j]=max(dp[i-1][j],dp[i-1][j-1]*2) if dp[i][j]>=10**18: print(-1) exit() print(dp[n][k])