#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <unordered_map>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)

using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
const int MAXN = 345;
double dp[MAXN][MAXN][MAXN];
bool visit[MAXN][MAXN][MAXN];

double dfs(int c1, int c2, int c3, int N) {
    if (visit[c1][c2][c3]) return dp[c1][c2][c3];
    visit[c1][c2][c3] = 1;
    if (!c1 && !c2 && !c3) return 0.0;
    int c0 = N - c1 - c2 - c3;
    double res = (double)c0 / N;
    if (c1) res += (dfs(c1 - 1, c2, c3, N) + 1) * ((double)c1 / N);
    if (c2) res += (dfs(c1 + 1, c2 - 1, c3, N) + 1) * ((double)c2 / N);
    if (c3) res += (dfs(c1, c2 + 1, c3 - 1, N) + 1) * ((double)c3 / N);
    return dp[c1][c2][c3] = ((double)N / (N - c0) * res);
}

int main() {
    int N;
    scanf("%d", &N);
    vector<int> cnt(4, 0);
    for (int i = 0; i < N; i++) {
        int a;
        scanf("%d", &a);
        cnt[a]++;
    }
    printf("%.10lf\n", dfs(cnt[1], cnt[2], cnt[3], N));
    return 0;
}
/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
by Benq;
*/

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
int main(void){
    int n;cin>>n;
    vector<vector<int>> a(n,vector<int>(n-1));
    rep(i,n)rep(j,n-1){
        cin>>a[i][j];
        a[i][j]--;
    }
    int f=0;
    vector<int> t(n,0);
    queue<int> que;
    rep(i,n)que.push(i);
    ll res=0;
    while(true){
        res++;
        queue<int> que2;
        bool used=false;
        vector<bool> ft(n,false);
        while(que.size()){
            int x=que.front();que.pop();
            if(ft[x])continue;
            int op=a[x][t[x]];
            if(ft[op])continue;
            if(a[op][t[op]]==x){
                used=true;
                ft[x]=ft[op]=true;
                t[x]++;t[op]++;
                if(t[x]==n-1)f++;
                else que2.push(x);
                if(t[op]==n-1)f++;
                else que2.push(op);
            }
        }
        if(!used){
            cout<<-1<<endl;
            return 0;
        }
        if(f==n){
            cout<<res<<endl;
            return 0;
        }
        swap(que,que2);
    }
}