#include <bits/stdc++.h>
using namespace std;
#define ll long double
const ll MOD = 1e9 + 7;
ll AllNegative=1;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll n,k;
cin >> n >> k;
vector<pair<ll,ll>> lst(n+1);
for(ll i=1;i<=n;i++){
cin >> lst[i].first >> lst[i].second;
if(lst[i].second!=-1) AllNegative=0;
}
sort(lst.begin(),lst.end());
ll total=0;
//cout << AllNegative << "\n";
for(ll i=1;i<=k;i++){
if(AllNegative==1){
total+=lst[i].first;
}
else{
total+=lst[i].first/i;
}
}
cout << total;
}