n,p,k=map(int,input().split()) x=10**18 g=-1 items=[tuple(map(int,input().split())) for i in range(n)] for i in range(k+1): f=p c=0 d=0 for j in range(n): t,b=items[j] if t==1: if c