#include <bits/stdc++.h>
using namespace std;

int main(){
  string a, b, c;
  cin >> a >> b >> c;
  map<char, int> m;
  string s = a + b + c;
  int ss = s.size();
  int kind = 0;
  vector<char> ch;
  for(int i = 0;i < ss;i++){
    m[s[i]]++;
    if(m[s[i]] == 1){
      kind++;
      ch.push_back(s[i]);
    }
  }
  if(kind > 10){
    cout << "UNSOLVABLE" << endl;
    return 0;
  }
  vector<int> per(10);
  int as = a.size();
  int bs = b.size();
  int cs = c.size();
  for(int i = 0;i < 10;i++)
    per[i] = i;
  int ap = pow(10, as - 1);
  int bp = pow(10, bs - 1);
  int cp = pow(10, cs - 1);
  int64_t po[10];
  for(int i = 0;i < 10;i++)
    po[i] = pow(10, i);
  for(int j = 0;j < 3628800;j++){
    next_permutation(per.begin(), per.end());
    for(int i = 0;i < kind;i++){
      m[ch[i]] = per[i];
    }
    int64_t h = 0;
    int64_t l = 0;
    int64_t ans = 0;
    for(int i = 0;i < as;i++)
      h += (m[s[as - 1 - i]] * po[i]);
    for(int i = 0;i < bs;i++)
      l += (m[s[as + bs - 1 - i]] * po[i]);
    for(int i = 0;i < cs;i++)
      ans += (m[s[ss - i - 1]] * po[i]);
    if(h < ap || l < bp || ans < cp)
      continue;
    if(h + l == ans){
      cout << h << endl;
      cout << l << endl;
      cout << ans << endl;
      return 0;
    }
  }
  cout << "UNSOLVABLE" << endl;
}
#include <bits/stdc++.h>
     
using namespace std;
#define fast_io ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define int long long
#define pb push_back
#define ll long long    
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rep1(i, n) for (ll i = n - 2; i >= 0; i--)
#define repi(i, n) for (ll i = 1; i <= n; i++)
#define repi1(i, n) for (ll i = n; i >= 1; i--)
#define mem(arr, x) memset(arr, x, sizeof(arr))
#define CLOCK cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";    
typedef vector<ll> vi;
typedef vector<char> vc;
#define mp make_pair
#define ss second
#define mod 1000000007
const int MAX = 1000000000;
const int inf = 1e18;
const long double PI = 3.141592653589793238460;

void solve()
{  
  
int n,k;
cin>>n>>k;
vector<pair<int,int>>v;
rep(i,n)
{  int p,q;
	cin>>p>>q;
	v.pb(mp(p,q));
}
sort(v.begin(),v.end());
int pai=k;
if(v[0].first>k)
{
	cout<<k<<'\n';
	return ;
}
k-=v[0].first;
int res=v[0].first;
if(n==1)
{
	cout<<res+v[0].second<<'\n';
	return;
}
//cout<<k;
map<int,int>m;
for(int i=1;i<n;i++)
{  k+=v[i-1].second;
	if(k<(v[i].first-v[i-1].first))
	{ 
	  res=v[i-1].first+k;
	  k=0;
	  break;
     }
     else
     {
     	k-=(v[i].first-v[i-1].first);
     	res=v[i].first;
     	m[v[i].first]++;
     //	k+=v[i].second;
     }
}
if(m[v[n-1].first])
k+=v[n-1].second;
if(k)
{
	res+=k;
}
cout<<res<<'\n';
}

     
int32_t main()
{
  fast_io;

int T=1;
//cin>>T;
while(T--)
{  
 solve(); 
}
 
 }