n,p,k=map(int,input().split()) x=10**18 q=[-1]*(k+1) q[0]=p for _ in range(n): t,b=map(int,input().split()) for i in reversed(range(k)): if q[i]!=-1: if t==2: b=q[i] if q[i]+b<=x: q[i+1]=max(q[i+1],q[i]+b) print(q[k])