#include <bits/stdc++.h>
//#include <atcoder/all>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define popcount __builtin_popcount
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
template <class T>
inline bool chmin(T &a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}

template <typename T>
T mypow(T x, T n, const T &p = -1)
{ //x^nをmodで割った余り
	T ret = 1;
	while (n > 0)
	{
		if (n & 1)
		{
			if (p != -1)
				ret = (ret * x) % p;
			else
				ret *= x;
		}
		if (p != -1)
			x = (x * x) % p;
		else
			x *= x;
		n >>= 1;
	}
	return ret;
}

ll gcd(ll n, ll m)
{
	ll tmp;
	while (m != 0)
	{
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m)
{
	return abs(n) / gcd(n, m) * abs(m); //gl=xy
}

using namespace std;
//using namespace atcoder;

struct UF {
	vector<int>par;//親
	vector<int>sz;//要素数

  UF(int n){
    sz.resize(n,1);
    par.resize(n);
    for(int i=0;i<n;++i){
      par[i]=i;
    }
  }

	//木の根を求める
	int find(int x) {
		if (par[x] == x) {
			return x;
		}
		else {
			return par[x] = find(par[x]);//経路圧縮
		}
	}

	//xとyの属する集合を併合
	bool unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y)return false;//すでに同じ集合に属している

		if (sz[x] < sz[y]) {//要素数が小さい方を下に
			par[x] = y;
      sz[y]+=sz[x];
		}
		else {
			par[y] = x;
			sz[x]+=sz[y];
		}
		return true;
	}

	//xとyが同じ集合に属するかを判定
	bool same(int x, int y) {
		return find(x) == find(y);
	}

    int size(int k){//要素数を求める
        return sz[find(k)];
    }
};


void solve()
{
	int n;
	cin>>n;
	vector<double>x(n),y(n);
	rep(i,n)cin>>x[i]>>y[i];
	double l=0,r=101;
	rep(q,100){
		double mid=(l+r)/2;
		UF tree(n);
		rep(i,n){
			REP(j,i+1,n){
				double dis=pow(x[i]-x[j],2)+pow(y[i]-y[j],2);
				if(mid*mid*4>dis){
					tree.unite(i,j);
				}
			}
		}
		vector<double>u(n),d(n);
		rep(i,n){
			chmax(u[tree.find(i)],min(100.0,y[i]+mid*2));
			chmin(d[tree.find(i)],max(-100.0,y[i]-mid*2));
		}
		bool ng=false;
		rep(i,n){
			if(u[i]==100.0&&d[i]==-100.0){
				ng=true;
			}
		}
		if(ng)r=mid;
		else l=mid;
	}
	cout<<l;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}

//#pragma GCC optimize ("O2")
//#pragma GCC target ("avx2")
#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

int num[8210];
int kazu[8210];
const int ma = (1 << 13) - 1;
int query(int n) {
	int n2 = (n & ma) + 1;
	while (num[n2]) {
		if (num[n2] == n + 1) return kazu[n2];
		n2 = n2 * 2 % 8209;
	}
	return 0;
}
void add(int n, int b) {
	int n2 = (n & ma) + 1;
	while (num[n2]) {
		if (num[n2] == n + 1) return;
		n2 = n2 * 2 % 8209;
	}
	num[n2] = n + 1;
	kazu[n2] = b;
}
int li[300];

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);


	int N, M;
	cin >> N >> M;
	int w[8];
	rep(i, N) cin >> w[i];

	pair<int, int> lv[100001];
	rep(i, M) {
		int l, v;
		cin >> l >> v;
		lv[i] = { v, l };
	}
	sort(lv, lv + M);
	lv[M] = { 1e9,1e9 };

	rep(i, 1 << N) {
		rep(j, N) if (i >> j & 1) li[i] += w[j];
	}
	sort(li, li + (1 << N));
	int saidai = 0;
	int k = 0;
	rep(i, 1 << N) {
		while (lv[k].first < li[i]) {
			if (saidai < lv[k].second) saidai = lv[k].second;
			k++;
		}
		add(li[i], saidai);
	}

	rep(i, N) {
		if (w[i] > lv[0].first) {
			printf("-1");
			return 0;
		}
	}
	int P[8];
	rep(i, N) P[i] = i;

	int kotae = 1e9;
	do {
		int tmp[8] = {};
		rep(p, N - 1) {
			int omosa = w[P[p]];
			for (int q = p + 1; q < N; q++) {
				omosa += w[P[q]];
				int kari = tmp[p] + query(omosa);
				if (tmp[q] < kari) tmp[q] = kari;
			}
		}
		if (kotae > tmp[N - 1]) kotae = tmp[N - 1];
		
	} while (next_permutation(P, P + N));

	printf("%d\n", kotae);

	Would you please return 0;
}