/*
原来的编码能力是p
现在有n到题目 每道题目有个难度值a 解决后编码能力加b
现在的编码能力大于等于a可以解决这道题
问 m天 每天最多解决1道题 天后编码能力最大为多少
优先队列
*/
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <queue>
#define inf 0x7f7f7f7f
using namespace std;
const int maxn = 100010;
struct node
{
int a;
int b;
friend bool operator<(node n1,node n2)
{
if(n1.a==n2.a)
return n1.b<n2.b;
return n1.a>n2.a;
}
};
int main()
{
int n,m,p;
while(scanf("%d%d%d",&n,&m,&p)!=EOF)
{
priority_queue<node>q1;
priority_queue<int>q2;//默认从大到小
node w;
for(int i=0; i<n; i++)
{
scanf("%d%d",&w.a,&w.b);
q1.push(w);
}
while(m--)
{
while(!q1.empty() && q1.top().a <= p)
{
q2.push(q1.top().b);
q1.pop();
}
if(q2.empty())
break;
p += q2.top();
q2.pop();
}
printf("%d\n",p);
}
return 0;
}