#include <bits/stdc++.h>
#include <stdlib.h>

#define sz(x) (int)(x).size()
using namespace std;

int64_t strtoll(string &s) {
    int64_t res = 0;
    for (int i = 0; i < sz(s); i++) {
        res *= 10;
        res += s[i] - '0';
    }
    return res;
}

vector<int64_t> convertToInts(vector<string> &arr, vector<int> &inds) {
    vector<string> results = arr;
    for (int i = 0; i < 3; i++) {
        for (auto &c : results[i]) {
            c = inds[c - 'a'] + '0';
        }
    }
    vector<int64_t> int_results(3);
    for (int i = 0; i < 3; i++) {
        int_results[i] = strtoll(results[i]);
    }
    return int_results;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    vector<string> arr(3);
    for (int i = 0; i < 3; i++) {
        cin >> arr[i];
    }
    vector<int> inds(26, -1);
    int cur = 0;
    for (int i = 0; i < 3; i++) {
        for (char c : arr[i]) {
            if (inds[c - 'a'] == -1) {
                inds[c - 'a'] = cur++;
            }
        }
    }
    if (cur > 10) {
        cout << "UNSOLVABLE\n";
        return 0;
    }
    int index = 0;
    while (cur != 10) {
        if (inds[index] == -1) {
            inds[index] = cur++;
        }
        index++;
    }
    vector<int> reverse_inds(cur, -1);
    for (int i = 0; i < 26; i++) {
        if (inds[i] == -1) {
            continue;
        }
        reverse_inds[inds[i]] = i;
    }
    sort(reverse_inds.begin(), reverse_inds.end());
    do {
        for (int i = 0; i < cur; i++) {
            inds[reverse_inds[i]] = i;
        }
        if (inds[arr[0][0] - 'a'] == 0) {
            continue;
        }
        if (inds[arr[1][0] - 'a'] == 0) {
            continue;
        }
        if (inds[arr[2][0] - 'a'] == 0) {
            continue;
        }
        vector<int64_t> results = convertToInts(arr, inds);
        if (results[0] + results[1] == results[2]) {
            for (int i = 0; i < 3; i++) {
                cout << results[i] << "\n";
            }
            return 0;
        }
    } while(next_permutation(reverse_inds.begin(), reverse_inds.end()));
    cout << "UNSOLVABLE\n";

    return 0;
}

 //
#include<bits/stdc++.h>

using namespace std;

#define PB push_back
#define f first
#define s second
#define what_is(x) cerr << #x << " is " << x << endl;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

const int INF = 1000000007;
const ll MOD = 1000000007;

void solve_test()
{
    int n;
    cin >> n;
    ll T;
    cin >> T;
    vector<ll> a(n);
    for(int i=0; i<n; i++)
    {
        cin >> a[i];
    }
    if(n == 1)
    {
        if(T >= a[0])
        {
            cout << a[0];
        }
        else
        {
            cout << 0;
        }
        return;
    }

    vector<ll> s1, s2;
    for(int i=0; i<(1<<(n/2)); i++)
    {
        ll t = 0;
        for(int j=0; j<n/2; j++)
        {
            if((1<<j)&i)
            {
                t += a[j];
            }
        }
        s1.PB(t);
    }

    for(int i=0; i<(1<<(n-n/2)); i++)
    {
        ll t = 0;
        for(int j=0; j<(n-n/2); j++)
        {
            if((1<<j)&i)
            {
                t += a[j+n/2];
            }
        }
        s2.PB(t);
    }
    s1.PB(0);
    sort(s2.begin(), s2.end());
    ll ans = 0;
    for(ll x : s1)
    {
        if(x <= T)
        {
            ans = max(ans, x);
        }
        auto a = upper_bound(s2.begin(), s2.end(), T-x);
        if(a != s2.begin())
        {
            a--;
//            what_is(x);
//            what_is((*a));
            ans = max(ans, x + (*a));
        }
    }
    cout << ans;
}

signed main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int tests;
    tests = 1;
    //cin >> tests;
    while(tests--)
    {
        solve_test();
    }
    return 0;
}
