/*
By: Anurag Rai
CF: Raag07
CC: call_me_raag
*/
#include<bits/stdc++.h>
#define FIO	   				std::ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(it, a, b)		for(int it = a; it < b; ++it)
#define all(X)				(X).begin(), (X).end()
#define int    				long long int
#define ff					first
#define ss					second
#define pb					push_back
#define sq(X)				(X) * (X)
#define mod    				1000000007
#define NUM					1000000
using namespace std;

// 1-D  <=>  2-D (N*M)
//  k   <->  [k / N, k % M]

int max(int a, int b) { return a > b ? a : b; }
int min(int a, int b) { return a < b ? a : b; }
int gcd(int a, int b) {	return b ? gcd(b, a % b) : a; }
bool comp(int a, int b) { return a > b; }
bool sortbySS(const pair<int, int> &A, const pair<int, int> &B) { return A.ss < B.ss; }


void solve() {
	// Write your code here

	string S;
	cin >> S;

	string res = "";

	for(int i = S.length(); i > 0; --i) {
		if(S[i-1] == '6')
			res += '9';
		else if(S[i-1] == '9')
			res += '6';
		else
			res += S[i-1];
	}

	cout << res << endl;
}

int32_t main() {
	FIO;

	int t = 1;
	// cin >> t;

	while (t--) {
		solve();
	}

	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define N 107
#define ldb long double
char s[N][N];
int g[N][N],cnt[N],n;
bool vis[N];
ldb f[N],cof[N];
void dfs(int v){
	cnt[v]++; vis[v]=1;
	for(int i=1;i<=n;i++)
		if(g[v][i]&&!vis[i])
			dfs(i);
}
int main(){
	//freopen("cpp.in","r",stdin);
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%s",s[i]+1);
		for(int j=1;j<=n;j++)
			g[i][j]=s[i][j]-'0';
	}
	for(int i=1;i<=n;i++){
		memset(vis,0,sizeof(vis));
		dfs(i);
	}
	ldb ans=0;
	for(int i=1;i<=n;i++)
		ans+=1.0/cnt[i];
	printf("%.10Lf\n",ans);
	return 0;
}
