#include <bits/stdc++.h>

using i32 = std::int32_t;
using i64 = std::int64_t;
using u32 = std::uint32_t;
using u64 = std::uint64_t;
using usize = std::size_t;

const i32 INF = 1001001001;
const i64 LINF = 1001001001001001;
const u32 MOD1 = 1000000007;
const u32 MOD2 = 998244353;

using namespace std;

int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    i64 k;
    string s,t;
    cin>>k>>s>>t;
    vector<i64> r(9,k);
    vector<i64> taka(9,0),aoki(9,0);
    for(i64 i=0;i<4;i++){
        r[(s[i]-'0')-1]--;
        r[(t[i]-'0')-1]--;
        taka[(s[i]-'0')-1]++;
        aoki[(t[i]-'0')-1]++;
    }
    i64 tp=0,ap=0;
    for(i64 i=0;i<9;i++){
        tp+=(i+1)*pow(10,taka[i]);
        ap+=(i+1)*pow(10,aoki[i]);
    }
    i64 sum=9*k-8;
    double ans=0;
    for(i64 i=0;i<9;i++){
        if(r[i]==0)continue;
        for(i64 j=0;j<9;j++){
            if(r[j]==0||(i==j&&r[j]<=1))continue;
            i64 ntp=tp-(i+1)*pow(10,taka[i]);
            i64 nap=ap-(j+1)*pow(10,aoki[j]);
            ntp+=(i+1)*pow(10,taka[i]+1);
            nap+=(j+1)*pow(10,aoki[j]+1);
            if(ntp>nap){
                ans+=((double)(r[i])/sum)*((double)((i!=j?r[j]:r[j]-1))/(sum-1));
            }
        }
    }
    cout<<fixed<<setprecision(12)<<ans<<endl;
}
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, n) for (ll i = s; i < (ll)(n); i++)

// DFSの実装例
bool vis[21];
ll par[21];
map<ll, vector<ll>> edges;
stack<ll> st;
vector<ll> con;
vector<vector<ll>> cons;
void dfs(ll num) {
  vis[num] = true;
  con.push_back(num);
  auto es = edges[num];
  for (auto e : es) {
    if (!vis[e]) {
      st.push(e);
      vis[e] = true;
      par[e] = num;
    }
  }
  while (!st.empty()) {
    auto top = st.top();
    st.pop();
    dfs(top);
  }
};

int main() {
  ll N, M;
  cin >> N >> M;
  rep(i, 0, M) {
    ll ai, bi;
    cin >> ai >> bi;
    edges[ai].push_back(bi);
    edges[bi].push_back(ai);
  }

  vis[0] = true;
  rep(i, 1, N + 1) {
    if (!vis[i]) {
      con = {};
      dfs(i);
      cons.push_back(con);
    }
  }

  ll ans = 1;
  for (auto co : cons) {
    map<ll, ll> col;
    ll comb = 0;
    col[co[0]] = 1; // 1 for red, 2 for green, 3 for blue;
    rep(bit, 0, 1 << (co.size() - 1)) {
      for (ll i = 1; i < (ll)co.size(); ++i) {
        ll flag = bit & (1 << (co.size() - 1 - i));
        if (col[par[co[i]]] == 1) {
          col[co[i]] = flag ? 3 : 2;
        } else if (col[par[co[i]]] == 2) {
          col[co[i]] = flag ? 3 : 1;
        } else if (col[par[co[i]]] == 3) {
          col[co[i]] = flag ? 2 : 1;
        }
      }
      bool abl = true;
      for (ll i = 0; i < (ll)co.size(); ++i) {
        for (auto edge : edges[co[i]]) {
          if (col[edge] == col[co[i]]) {
            abl = false;
            break;
          }
          if (abl == false)
            break;
        }
      }
      if (abl) {
        comb += 1;
      }
    }
    comb *= 3;

    ans *= comb;
  }
  cout << ans << endl;
}
