#include<bits/stdc++.h>
using namespace std;
struct p{
int type,a;
}c[5005];
int dp[5005];
int main()
{
int n,k,x;
cin>>n>>k>>x;
for(int i=1;i<=n;i++){
cin>>c[i].type >>c[i].a;
}
int maxx=-1,max_;
for(int i=1;i<=n;i++){
if(c[i].type==2 && x>=1900) ;
else{
if(x+floor((c[i].a-x)/4.0)>maxx){
maxx=x+floor((c[i].a-x)/4.0);
max_=i;
}
}
}
dp[1]=maxx;
int dq=max_;
for(int i=2;i<=k;i++){
int maxx1=-1,max_1;
for(int j=dq+1;j<=n;j++){
if(c[i].type==2 && x>=1900) ;
else{
if(x+floor((c[i].a-x)/4.0)>maxx){
maxx1=x+floor((c[i].a-x)/4.0);
max_1=i;
}
}
}
dp[i]=maxx1;
dq=max_1;
}
int maxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=-1;
for(int i=1;i<=k;i++){
if(dp[i]>maxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx){
maxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=dp[i];
}
}
cout<<maxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;
return 0;
}