#include <bits/stdc++.h>
#define int long long
#define maxn 50010
using namespace std;
struct node {
int p, c, pos;
bool operator < (const node &b) const {
return c > b.c;
}
} a[maxn];
struct node2 {
int cha, pos, c, p;
bool operator < (const node2 &b) const {
return cha > b.cha;
}
};
bool cmp(node a, node b) {
return a.p < b.p;
}
bool vis[maxn];
priority_queue<node> q;
priority_queue<node2> q1;
int n, k;
int m;
int ans;
signed main() {
scanf("%lld %lld %lld", &n, &k, &m);
for (int i = 1; i <= n; i++) {
scanf("%lld %lld", &a[i].p, &a[i].c);
a[i].pos = i;
q.push(a[i]);
}
memset(vis, false, sizeof vis);
while (k--) {
m -= q.top().c;
if (m <= 0) {
break;
} else vis[q.top().pos] = true, ans++, q1.push({q.top().p - q.top().c, q.top().pos, q.top().c, q.top().p});
q.pop();
}
if (m < 0) {
printf("%lld", ans);
return 0;
}
sort(a + 1, a + 1 + n, cmp);
for (int i = 1; i <= n; i++) {
if (vis[a[i].pos]) continue;
if (q1.size() && a[i].p >= q1.top().p - q1.top().c + q.top().c) {
m -= q1.top().p - q1.top().c + q.top().c;
if (m >= 0) q1.pop(), q.pop(), ans++, i--;
else break;
} else {
m -= a[i].p;
q.pop(), q1.pop();
if (m > 0) ans++;
else break;
}
}
cout << ans;
return 0;
}