import collections,sys,math,functools,operator,itertools,bisect,heapq,decimal,string,time,random #sys.setrecursionlimit(10**9) #sys.set_int_max_str_digits(0) input = sys.stdin.readline #n = int(input()) #alist = list(map(int,input().split())) #alist = [] #s = input() n,p,k = map(int,input().split()) item =[list(map(int,input().split())) for i in range(n)] dp = [[-10**18 for i in range(k+1)] for j in range(n+1)] dp[0][0] = p for i in range(n): for j in range(k+1): dp[i][j] = min(dp[i][j],10**18) if dp[i][j] == -10**18: continue dp[i+1][j] = max(dp[i+1][j],dp[i][j]) if j+1<=k: if item[i][0] == 1: dp[i+1][j+1] = max(dp[i+1][j+1],dp[i][j] + item[i][1]) else: dp[i+1][j+1] = max(dp[i+1][j+1],dp[i][j] * 2) print(dp[-1][-1] if dp[-1][-1] < 10**18 else -1)