#include <iostream>
#include <string>
#include<math.h>
#include<vector>
#include<algorithm>

using ll = long long;
using namespace std;
int main(void) {
	ll n, k; cin >> n >> k;
	ll ans=0;
	ll before=0;
	vector<vector<ll>> a(n,vector<ll>(2)); for (int i = 0; i < n; i++) cin >> a[i][0]>>a[i][1];
	sort(a.begin(), a.end());
	for (int i = 0; i < n; i++) {
		if (k < (a[i][0]-before)) {
			ans += k;
			k = 0;
			break;
		}
		else {
			k += (a[i][1] + before - a[i][0]);
			ans =a[i][0];
		}
		before = a[i][0];
	}
	if (k != 0)ans += k;
	cout << ans << endl;
	return 0;
}
#include<iostream>
#include<cstring>
#include<algorithm>
#define int long long

using namespace std;

int a[101];
int g1(int x)
{
	if(x==0)return 0;
	int cnt=0;
	while(x)
	{
		a[++cnt]=x%10;
		x/=10;
	}
	sort(a+1,a+1+cnt);
	int ans=0;
	for(int i=cnt;i>=1;i--)
	{
		ans*=10;
		ans+=a[i];
	}
	return ans;
}

int g2(int x)
{
	if(x==0)return 0;
	int cnt=0;
	while(x)
	{
		a[++cnt]=x%10;
		x/=10;
	}
	sort(a+1,a+1+cnt);
	int ans=0;
	for(int i=1;i<=cnt;i++)
	{
		ans*=10;
		ans+=a[i];
	}
	return ans;
}

signed main()
{
	int N,K;cin>>N>>K;
	for(int i=1;i<=K;i++)
	{
		int tmp=g1(N)-g2(N);
		N=tmp;
	}
	cout<<N;
	return 0;
}