#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <math.h> // sqrt
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <iomanip> // setprecision
#include <bitset> // bitset
#include <functional> // greater,int>()
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<long long>;
using pii = pair<int, int>;
using psi = pair<string, int>;
#define rep(i, n) for(ll i = 0; i < (ll) n; i++)
#define FOR(i, a, b) for(ll i = a; i < (ll) b; i++)
#define ALL(x) x.begin(),x.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define YESNO(T) if(T){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define yesno(T) if(T){cout<<"yes"<<endl;}else{cout<<"no"<<endl;}
#define YesNo(T) if(T){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
#define COUT(ans) cout<<ans<<endl;
#define COUTD(ans) cout<<fixed<<setprecision(10)<<ans<<endl;

int i;
bool check;

ll f (map<char,int> &m, string s, vll &a) {
    ll ans = 0;
    for (char c : s) {
        ll num = 0;
        if (m.count(c)) {
            num = m.at(c);
        }
        else {
            num = a[i];
            m[c] = a[i];
            i++;
        }
        ans *= 10;
        ans += num;
        if (ans == 0) {
            check = true;
            return 0;
        }
    }
    return ans;
}

int main() {
    string s1, s2, s3;
    cin >> s1 >> s2 >> s3;
    vi data(26, 0);
    for(char c :s1) {
        int a = c - 'a';
        data[a]++;
    }
    for (char c : s2) {
        int a = c - 'a';
        data[a]++;
    }
    for (char c : s3) {
        int a = c - 'a';
        data[a]++;
    }
    int count = 0;
    rep(i, 25) {
        if (data[i] > 0) {
            count++;
        }
    }
    if (count > 10) {
        COUT("UNSOLVABLE")
        return 0;
    }
    vll a = {1,0,2,3,4,5,6,7,8,9};
    bool finish = false;
    do {
        i = 0;
        check = false;
        map<char, int> m;
        ll n1 = f(m, s1, a);
        ll n2 = f(m, s2, a);
        ll n3 = f(m, s3, a);
        if (check) {
            continue;
        }
        if (n1 + n2 == n3) {
            COUT(n1)
            COUT(n2)
            COUT(n3)
            finish = true;
            break;
        }
    } while(next_permutation(a.begin(), a.end()));
    if (!finish) {
        COUT("UNSOLVABLE")
    }
}

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

#define II pair<int, int>
#define III pair<II, int>
#define X first.first
#define Y first.second
#define Z second
#define all(a) (a).begin(), (a).end()
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)

int const oo = 1000000007, e5 = 100007, e6 = 1000007;
int N, M;
vector<int> edges[2005];
bool visited[2005];
int res = 0;

int __init__() {
    return 0;
}

void print01(int val, int showNums = 20) {
    char answer[showNums];
    for0(i, showNums) {
        answer[showNums - 1 - i] = val % 2 + '0';
        val /= 2;
    }
    cout << answer;
}

void DFS(int node) {
    if (visited[node]) return;
    ++res;
    visited[node] = 1;
    for0(i, edges[node].size()) {
        DFS(edges[node][i]);
    }
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);__init__();
    // freopen("test.txt", "r", stdin);
    int a, b;
    cin >> N >> M;
    for0(i, M) {
        cin >> a >> b;
        edges[a].push_back(b);
    }
    for1(i, N) {
        for1(i, N) visited[i] = 0;
        DFS(i);
    }
    cout << res;
}
