#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD =  998244353;
#define rep(i,a,b) for(ll i=a;i<b;++i) 
#define pii pair<ll,ll>

ll ar[8];

ll pow(ll a,ll b)
{
    return ar[b];
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ar[0] = 1;
    rep(i,1,8)
    ar[i] = ar[i-1]*10;
    ll k;
    cin>>k;
    string s,t;
    cin>>s>>t;
    ll a[9]={0},b[9]={0},a1=0,b1=0;
    rep(i,0,s.size()-1)
    a[s[i]-'1']++;
    rep(i,0,t.size()-1)
    b[t[i]-'1']++;
    rep(i,0,9)
    a1+=(i+1)*(ll)pow(10,a[i]);
    rep(i,0,9)
    b1+=(i+1)*(ll)pow(10,b[i]);
    ll num=0,d=0;
    rep(i,0,9)
    {
        rep(j,0,9)
        {
            ll r1 = k-a[i]-b[i],r2 = k-b[j]-a[j];
            if(!r1 || !r2) continue;
            (i!=j)?d+=(r1*r2):d+=((r1*(r1-1)));
            ll t1 = -1*(i+1)*(ll)pow(10,a[i]);
            t1 += (i+1)*(ll)pow(10,a[i]+1);
            ll t2 = -1*(j+1)*(ll)pow(10,b[j]);
            t2 += (j+1)*(ll)pow(10,b[j]+1);
            if(a1+t1>b1+t2) (i!=j)?num+=(r1*r2):num+=((r1*(r1-1)));
        }
    }
    printf("%0.12f\n",(double)num/d);
}
    
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false)
#define rep(i, n) for(ll i=0; i<(ll)n; i++)
#define ALL(obj) begin(obj), end(obj)
typedef long long ll;
vector<vector<int> > G(22);
vector<int> color(22, -1), ts;
vector<bool> vis(22, 0); 
int n, m, a, b;

void dfs(int now){
	ts.push_back(now);
	vis[now]=1;
	
	for(int i: G[now]){
		if(vis[i])
		    continue;
		    
		dfs(i);
	}
}

ll DFS(int i){
	if(i==ts.size())
	    return 1;
	
	ll res=0;
    rep(j, 3){
    	bool f=1;
    	for(int x:G[ts[i]]){
    		if(color[x]==j){
    			f=0;
    			break;
			}
		}
		
		if(!f)
		   continue;
		   
		color[ts[i]]=j;
		res+=DFS(i+1);
		color[ts[i]]=-1;
	}
	
	return res;
}

int main()
{
    IOS;
	cin>>n>>m;
	rep(i, m){
		cin>>a>>b;
		a--;
		b--;
		
		G[a].push_back(b);
		G[b].push_back(a);
	}	
	
	ll ans=1;
	rep(i, n){
		if(vis[i])
		    continue;
		
		dfs(i);
		fill(ALL(color), -1);
		ans*=DFS(0);
		ts.clear();
	}
	
	cout<<ans<<endl;
	
	return 0;
}