//Never stop trying
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

typedef string str;
typedef long long ll;
#define int ll
typedef double db;
typedef long double ld;
typedef pair<int, int> pi;
#define fi first
#define se second
typedef vector<int> vi;
typedef vector<pi> vpi;
typedef vector<str> vs;
typedef vector<ld> vd;
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define endl "\n"

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

const int MOD = 1e9 + 7; //998244353
const ll INF = 1e18;
const int MX = 2e5 + 10;
const int nx[4] = {0, 0, 1, -1}, ny[4] = {1, -1, 0, 0}; //right left down up

template<class T> using V = vector<T>;
template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

ll cdiv(ll a, ll b) { return a / b + ((a ^ b) > 0 && a % b); } // divide a by b rounded up
constexpr int log2(int x) { return 31 - __builtin_clz(x); } // floor(log2(x))

#define dbg(x) cerr << " - " << #x << " : " << x << endl;
#define dbgs(x,y) cerr << " - " << #x << " : " << x << " / " << #y << " : " << y << endl;
#define dbgv(v) cerr << " - " << #v << " : " << endl << "[ "; for(auto it : v) cerr << it << ' '; cerr << ']' << endl;

void IO() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

int N,M; 
int X[10][10];
int memo[10];

int solve(int i){
	if(memo[i]!=-1) return memo[i];
	int ans=0;
	FOR(j,i+1,N) ckmax(ans,solve(j)+X[i][j]);
	return memo[i]=ans;
}

int32_t main() {
	boost; IO();

	cin>>N>>M;
	vi w(N);
	FOR(i,0,N) cin>>w[i];
	sort(all(w));

	vpi vec;
	int mn_v=INF;
	FOR(i,0,M){
		int l,v; cin>>l>>v;
		ckmin(mn_v,v);
		vec.pb({v,l});
	}
	vec.pb({0,0});
	sort(all(vec));

	int mx[sz(vec)];
	FOR(i,0,sz(vec)){
		mx[i]=vec[i].se;
		if(i) ckmax(mx[i],mx[i-1]);
	}

	if(mn_v<w[N-1]){
		cout << -1 << endl;
		return 0;
	}
	
	int ans=INF;

	do{
		int pref[N];
		FOR(i,0,N){
			pref[i]=w[i];
			if(i) pref[i]+=pref[i-1];
		}     
		
		FOR(i,0,N) FOR(j,i+1,N){
			int W=pref[j]; if(i) W-=pref[i-1];

			int idx; //max i such that vec[i].fi<W
			int l=0,r=sz(vec)-1;
			while(l<=r){
				int m=(l+r)/2;
				if(vec[m].fi<W){
					idx=m; l=m+1;
				}
				else r=m-1;
			}
			X[i][j]=mx[idx];
		}

		memset(memo,-1,sizeof(memo));
		ckmin(ans,solve(0));
		
	}while(next_permutation(all(w)));

	cout << ans << endl;


	return 0;
}

/* Careful!!!
	.Array bounds
	.Infinite loops
	.Uninitialized variables / empty containers
	.Order of input

   Some insights:
	.Binary search
	.Graph representation
	.Write brute force code
	.Change your approach
*/

#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<ctime>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<bitset>
#define sqr(x) ((x)*(x))
#define fz1(i,n) for ((i)=1;(i)<=(n);(i)++)
#define fd1(i,n) for ((i)=(n);(i)>=1;(i)--)
#define fz0g(i,n) for ((i)=0;(i)<=(n);(i)++)
#define fd0g(i,n) for ((i)=(n);(i)>=0;(i)--)
#define fz0k(i,n) for ((i)=0;(i)<(n);(i)++)
#define fd0k(i,n) for ((i)=(long long)((n)-1);(i)>=0;(i)--)
#define fz(i,x,y) for ((i)=(x);(i)<=(y);(i)++)
#define fd(i,y,x) for ((i)=(y);(i)>=(x);(i)--)
#define fzin fz1(i,n)
#define fzim fz1(i,m)
#define fzjn fz1(j,n)
#define fzjm fz1(j,m)
#define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();++itr)
#define pb push_back
#define mk make_pair
#define rdst(st,len){static char ss[len];scanf(" %s",ss);(st)=ss;}
#define spln(i,n) (i==n?'\n':' ')
#define fac_init(n){fac[0]=fac[1]=inv[1]=fi[0]=fi[1]=1;fz(i,2,n){fac[i]=1ll*fac[i-1]*i%mod;inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;fi[i]=1ll*fi[i-1]*inv[i]%mod;}}
using namespace std;
inline void read(int &x)
{
	char c;int f=1;
	while(!isdigit(c=getchar()))if(c=='-')f=-1;
	x=(c&15);while(isdigit(c=getchar()))x=(x<<1)+(x<<3)+(c&15);
	x*=f;
}
int n,m,i,j,k,g[105][105];
double ans;
int main()
{
	cin>>n;
	fz1(i,n){
		fz1(j,n){
			char c;
			cin>>c;
			g[i][j]=((i==j)||(c&1));
		}
	}
	fz1(k,n){
		fz1(i,n)fz1(j,n)g[i][j]|=(g[i][k]&g[k][j]); 
	}
	fz1(i,n){
		int s=0;
		fz1(j,n)s+=g[j][i];
		ans+=1.0/s;
	}
	printf("%.12lf\n",ans);
	return 0;
}







