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

#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pair<int,int>>
#define vpll vector<pair<ll,ll>>
#define fr(i,k,n) for (int i = k; i < n; ++i)
#define fri(i,k,n) for (int i = k; i >= n; --i)
#define pb push_back
#define mp make_pair
#define all(arr) arr.begin(),arr.end()
#define ff first
#define ss second

const double pi=3.1415926535897932384626433832795;
const int inf=1e9;
const ll inf2=1e18;
const int mod=1e9+7;

void boost(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

int adj[20][20],n;
vi dp(1<<20,inf);

void solve(){
	int m;
	cin>>n>>m;
	int u,v;
	fr(i,0,m){
		cin>>u>>v;
		u--;
		v--;
		adj[u][v]=adj[v][u]=1;
	}
	for(int i=1;i<(1<<n);i++){
		if(!(i&(i-1))){
			dp[i]=1;
			continue;
		}
		dp[i]=1;
		for(int j=0;j<n;j++){
			if((i>>j)&1){
				for(int k=j+1;k<n;k++){
					if((i>>k)&1){
						if(adj[j][k]==0)
							dp[i]=inf;
					}
				}
			}
		}
		for(int j=(i-1)&i;j;j=(j-1)&i){
			dp[i]=min(dp[i],dp[j]+dp[i^j]);
		}
	}
	cout<<dp[(1<<n)-1]<<endl;
	return;
}

int main()
{
	boost();
	
	int tc=1;
	//cin>>tc;
	while(tc--)
		solve();
	return 0;
}
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const int inf = 1e9;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = b - 1; i >= a; i--)
using pint = pair<ll, ll>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};


//snukeさんの答え
int main() {
    vector<string> s(3);
    rep(i, 0, 3) cin >> s[i];
    map<char, ll> mp;
    set<char> heads;
    rep(i, 0, 3) {
        reverse(s[i].begin(), s[i].end());
        ll t = 1;
        if (i == 2) t = -1;
        for (char c : s[i]) {
            mp[c] += t;
            t *= 10;
        }
        reverse(s[i].begin(), s[i].end());
        heads.insert(s[i][0]);
    }
    if (mp.size() > 10) {
        cout << "UNSOLVABLE\n";
        return 0;
    }

    vector<int> p(10);
    iota(p.begin(), p.end(), 0);
    do {
        int i = 0;
        ll sum = 0;
        for (auto x : mp) {
            char c = x.first;
            ll t = x.second;
            sum += t * p[i];
            if (p[i] == 0 && heads.count(c) != 0) sum += 1e15;
            ++i;
        }
        if (sum == 0) {
            i = 0;
            for (auto &x : mp) {
                x.second = p[i];
                ++i;
            }
            // if (mp[s[0][0]] == 0 || mp[s[1][0]] == 0 || mp[s[2][0]] == 0) continue;
            rep(i, 0, 3) {
                rep(j, 0, s[i].size()) {
                    cout << mp[s[i][j]];
                }
                cout << "\n";
            }
            return 0;
        }
    } while (next_permutation(p.begin(), p.end()));

    cout << "UNSOLVABLE\n";
}