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

#define foo ios_base::sync_with_stdio(0),cin.tie(nullptr),cout.tie(nullptr)

#define ll long long

using namespace std;


ll makeInt(vector<int> v){
    reverse(v.begin(), v.end());
    int decimal = 1;
    int total = 0;
    for (auto& it : v)
    {
        total += it * decimal;
        decimal *= 10;
    }
    return total;
} 

vector<int> makearray(ll n){
    
    vector<int> a;
    
    while(n > 0)
    {
        a.push_back(n%10);
        
        n/=10;
    }
    return a;
    
}


void sol(){
   
   ll n;
   ll k;
   cin>>n>>k;
   
   
   
  vector<int> t;
  ll a, b;
   while(k--){
       
       t = makearray(n);
       sort(t.begin(),t.end());
       a = makeInt(t);
       sort(t.begin(),t.end(),greater<int>());
       b = makeInt(t); 
      
       
       n = abs(a-b);
        
        
      
       
   }
   
   cout<<n;
}




int main() {
	foo;

	    sol();
	
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i = (a); i < (b); ++i)
#define rrep(i,a,b) for(int i = (b); i --> (a);)
#define all(v) (v).begin(),(v).end()
#define trav(x,v) for(auto &x : v)
#define sz(v) int(v.size())
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long double ld;

int main(){
	cin.sync_with_stdio(0);
	cin.tie(0);
	cin.exceptions(cin.failbit);

	int n;
	cin >> n;

	vector<string> ss(n);
	trav(s, ss) cin >> s;

	ld ans = 0;
	rep(i,0,n){
		vector<bool> vis(n, false);
		stack<int> st;
		vis[i] = true;
		st.push(i);
		while(!st.empty()){
			int j = st.top(); st.pop();
			rep(k,0,n) if(ss[k][j]=='1' && !vis[k]){
				vis[k] = true;
				st.push(k);
			}
		}
		ans += ld(1) / count(all(vis), true);
	}
	cout.precision(12);
	cout << ans << endl;
}
