#include <bits/stdc++.h>          
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repp(i, st, en) for (ll i = (ll)st; i < (ll)(en); i++)
#define repm(i, st, en) for (ll i = (ll)st; i >= (ll)(en); i--)
#define all(v) v.begin(), v.end()
void chmax(ll &x, ll y) {x = max(x,y);}
void chmin(ll &x, ll y) {x = min(x,y);}
void Yes() {cout << "Yes" << endl; exit(0);}
void No() {cout << "No" << endl; exit(0);}
template<class in_Cout> void Cout(in_Cout x) {cout << x << endl; exit(0);}
template<class in_vec_cout>
void vec_cout(vector<in_vec_cout> vec) {
    for (in_vec_cout res : vec) {cout << res << " ";}
    cout << endl;
}

const ll inf = 1e18;
const ll mod = 1e9 + 7;

int main() {
    vector<string> S(3);
    rep(i,3) cin >> S[i];

    map<char,bool> used;
    rep(i,3) rep(j,S[i].size()) used[S[i][j]] = true;

    if (used.size()>10) Cout("UNSOLVABLE");

    vector<ll> num(10);
    rep(i,10) num[i] = i;

    do {
        map<char,ll> id;
        ll index = 0;
        for (auto p : used) {
            id[p.first] = num[index];
            index++;
        }

        vector<ll> N(3);
        bool NG = false;
        rep(i,3) {
            if (id[S[i][0]]==0) NG = true;
            rep(j,S[i].size()) N[i] = N[i]*10 + id[S[i][j]];
        }
        if (NG) continue;
        if (N[0]+N[1]==N[2]) {
            rep(i,3) cout << N[i] << endl;
            return 0;
        }
    } while (next_permutation(all(num)));

    Cout("UNSOLVABLE");
}
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for (int i = (m); i < (int)(n); i++)
using ll = long long;


ll solve(ll b, ll c) {
    if (b == 0) return 1 + c / 2 + (c - 1) / 2;
    ll ret = 2;
    if (b > 0) ret += (c - 1) / 2 + (c - 2) / 2;
    else ret += c / 2 + (c - 1) / 2;

    if (b < 0) {
        b *= -1;
        c--;
    }
    ll l = max(-b + 1, b - c / 2);
    ll r = min(b, (c - 1) / 2 - b + 1);
    if (l <= r) ret += 2 * b - 1;
    else ret += (b - l) + (b + r - 1);
    return ret;
}


int main() {
    // input
    ll B, C;
    cin >> B >> C;

    //solve
    ll ans = solve(B, C);
    cout << ans << endl;
}
