/**
 * Author: Daniel
 * Created Time: 2021-04-12 12:44:39
**/

#include <bits/stdc++.h>

using namespace std;

#define F first 
#define S second
#define ER erase
#define IS insert
#define PI acos(-1)
#define PB pop_back
#define MP make_pair
#define MT make_tuple
#define LB lower_bound
#define UB upper_bound
#define EB emplace_back
#define lowbit(x) (x & -x)
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(), x.end()
#define RALL(x) x.rbegin(), x.rend()
#define SOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout<<fixed<<setprecision(10)

typedef long long LL;
typedef vector<LL> VL;
typedef vector<int> VI;
typedef vector<bool> VB;
typedef pair<LL, LL> PLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef unsigned long long ULL;
typedef pair<double, double> PDD;
typedef vector<pair<LL, LL> > VPLL;
typedef vector<pair<int, int> > VPII;

template <typename A> using VE = vector<A>;
template <typename A> using USET = unordered_set<A>;
template <typename A> using HEAP = priority_queue<A>;
template <typename A, typename B> using PA = pair<A, B>;
template <typename A, typename B> using UMAP = unordered_map<A, B>;
template <typename A> using RHEAP = priority_queue<A, vector<A>, greater<A> >;

template <typename A> A MAX(const A &a) { return a; }
template <typename A> A MIN(const A &a) { return a; }
template <typename A> A MAX(const A *a, const A *b) { return *max_element(a, b); }
template <typename A> A MIN(const A *a, const A *b) { return *min_element(a, b); }
template <typename A, typename... B> A MAX(const A &a, const B&... b) { return max(a, MAX(b...)); }
template <typename A, typename... B> A MIN(const A &a, const B&... b) { return min(a, MIN(b...)); }
template <typename A, typename B = typename std::iterator_traits<A>::value_type> B MAX(A a, A b) { return *max_element(a, b); }
template <typename A, typename B = typename std::iterator_traits<A>::value_type> B MIN(A a, A b) { return *min_element(a, b); }

mt19937 rng((unsigned int)chrono::steady_clock::now().time_since_epoch().count());

///////////////////////////////////////////////////////////////////////////
//////////////////// DO NOT TOUCH BEFORE THIS LINE ////////////////////////
///////////////////////////////////////////////////////////////////////////

// check the limitation!!!
const int N = 100010, M = 1010;



// read the question carefully!!!
int main()
{
    SOS;

    VS g(3);
    for (auto &s : g) cin >> s;
    map<char, int> mp;
    int t = 0;
    for (auto &s : g)
        for (auto &c : s)
            if (!mp.count(c))
                mp[c] = t ++ ;
    if (SZ(mp) > 10)
    {
        cout << "UNSOLVABLE\n";
        return 0;
    }
    VL p(10);
    iota(ALL(p), 0LL);
    auto get = [&](string s) -> string
    {
        string res;
        for (auto &c : s) res += (char)(p[mp[c]] + '0');
        return res;
    };
    auto calc = [&](string s) -> LL
    {
        return stol(s);
    };
    do
    {
        VS b(3);
        bool flag = true;
        for (int i = 0; i < 3; i ++ ) 
        {
            b[i] = get(g[i]);
            flag &= (b[i][0] != '0');
        }
        if (!flag) continue;
        VL a(3);
        for (int i = 0; i < 3; i ++ ) a[i] = calc(b[i]);
        if (a[0] > 0 && a[1] > 0 && a[2] > 0 && a[0] + a[1] == a[2])
        {
            for (auto &u : a)
                cout << u << '\n';
            return 0;
        }
    } while (next_permutation(ALL(p)));
    cout << "UNSOLVABLE\n";
    return 0;
}

// GOOD LUCK!!!

//noob
#include<bits/stdc++.h>
using namespace std;
#define f0(i,a,n) for(int i=a;i<n;i++)
#define f1(i,a,n) for(int i=a;i<=n;i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long int 
#define ld long double
#define ull unsigned long long int
#define pi acos(-1)
#define test() int T,t=1;cin>>T;
#define all(x) (x).begin(),(x).end()
#define sz(x) (int(x.size()))
typedef vector<int> vi;
typedef pair<int,int> PI;

const int INF = 1e9 + 5;

template<typename T> void out(const T& t){std::cout << t << "\n";}
template <typename T>
void print_vector(const vector<T>& V){
  for(int i=0; i < V.size(); i++)
    cout << V[i] << " ";
  cout<<endl;
}

//function
int gcd(int a,int b);

void solve(){
	int a,b,sa=0,sb=0;cin>>a>>b;
	while(a) sa+=a%10,a/=10;
	while(b) sb+=b%10,b/=10;
	out(max(sa,sb));
}
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
int t=1;
while(t--)
solve();
	return 0;
}
int gcd(int x, int y) {
	return y == 0 ? x : gcd(y, x % y);
}
