#include <stdio.h>
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
using namespace std;

pair <long long, long long> p[100005];
vector <long long> v;
set <pair <long long, int> > s;

int main()
{
	ios::sync_with_stdio(false);
	freopen("castle.in", "r", stdin);
	freopen("castle.out", "w", stdout);
	long long n, S;
	cin >> n >> S;
	long long sum = 0;

	for (long long i = 0; i < n; i++)
	{
		cin >> p[i].second >> p[i].first;
	}
	sort(p, p + n);
	                
	long long i = n - 1;
	for (; i >= 0; i--)
	{
		if (S == 0)
		{
			s.insert(make_pair(p[i].first, i));
			sum += p[i].second;
			continue;
		}
		if (s.size() > 0)
		{
			while (S > 0 && s.size() > 0 && (*(s.rbegin())).first > p[i].first)
			{
				pair <long long, int> r = *(s.rbegin());
				S--;
				s.erase(r);
				sum -= r.first;
			}	
		}
		if (p[i].second / p[i].first <= S)
		{
			S -= p[i].second / p[i].first;
			//v.push_back(p[i].second % p[i].first);
			s.insert(make_pair(p[i].second % p[i].first, i));
			sum += p[i].second % p[i].first;
		}
		else
		{
			//v.push_back(p[i].second - S * p[i].first);
			sum += p[i].second - S * p[i].first;
			S = 0;	
		}  
	}               
	if (S == 0)
	{
		cout << sum << endl;
		return 0;
	}                            
	while (S > 0 && s.size() > 0)
	{
		pair <long long, int> r = *(s.rbegin());
		s.erase(r);
		sum -= r.first;
		S--;
	}
	cout << sum << endl;
                    
	return 0;
}