#include <iostream>
#include <algorithm>
using namespace std;

int n, w[19], l[100009], v[100009], lp[309], pr[19];
long long ans = 1e18, d[19];
bool vs[19];

void ps()
{
	d[0] = 0;
	for (int i = 1; i < n; i++) {
		int s = (1 << pr[i]);
		d[i] = d[i - 1];
		for (int j = i - 1; j >= 0; j--) {
			s += (1 << pr[j]);
			d[i] = max(d[i], d[j] + 1LL * lp[s]);
		}
	}
	ans = min(ans, d[n - 1]);
}

void fg(int pi)
{
	if (pi == n) {
		ps();
		return;
	}
	for (int i = 0; i < n; i++) {
		if (vs[i]) continue;
		vs[i] = true; pr[pi] = i;
		fg(pi + 1);
		vs[i] = false;
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int m; cin >> n >> m;
	int mx = 0;
	for (int i = 0; i < n; i++) {
		cin >> w[i];
		mx = max(mx, w[i]);
	}
	bool f = true;
	for (int i = 0; i < m; i++) {
		cin >> l[i] >> v[i];
		if (v[i] < mx) f = false;
	}
	if (!f) {
		cout << -1 << '\n';
		return 0;
	}
	for (int i = 0; i < (1 << n); i++) {
		long long s = 0;
		for (int j = 0; j < n; j++)
			if ((1 << j) & i)
				s += w[j];
		for (int j = 0; j < m; j++)
			if (v[j] < s)
				lp[i] = max(lp[i], l[j]);
	}
	fg(0);
	cout << ans << '\n';
	return 0;
}
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 4000000000000000000 //オーバーフローに注意
#define MOD 1000000007
//#define MOD 998244353
#define EPS 0.000000001
using namespace std;


struct Info{
	Info(){

		len = value = 0;
	}
	Info(ll arg_len,ll arg_value){
		len = arg_len;
		value = arg_value;
	}
	bool operator<(const struct Info& arg) const{
		if(len != arg.len){

			return len < arg.len;
		}else{

			return value > arg.value;
		}

	}

	ll len,value;
};

ll N,M;
ll W[10],work[10];
ll max_dist[10][10];
Info info[100005];
vector<Info> V;

int main(){

	scanf("%lld %lld",&N,&M);

	ll max_W = 0;

	for(ll i = 0; i < N; i++){

		scanf("%lld",&W[i]);
		max_W = max(max_W,W[i]);
	}

	for(ll i = 0; i < M; i++){

		scanf("%lld %lld",&info[i].len,&info[i].value);
		if(info[i].value < max_W){

			printf("-1\n");
			return 0;
		}
	}

	sort(info,info+M);

	ll mini = HUGE_NUM;
	for(int i = M-1; i >= 0; i--){
		if(info[i].value < mini){
			mini = info[i].value;
			//printf("len:%lld value:%lld\n",info[i].len,info[i].value);
			V.push_back(info[i]);
		}
	}

	ll ans = HUGE_NUM;

	vector<int> vec;
	for(int i = 0; i < N; i++){

		vec.push_back(i);
	}

	do{

		for(ll i = 0; i < N; i++){

			work[i] = 0;
		}

		ll table[10];
		for(ll i = 0; i < N; i++){

			table[i] = W[vec[i]];
			if(i == 0)continue;

			table[i] += table[i-1];
		}


		for(ll i = 1; i < N; i++){
			for(ll base = 0; base <= i-1; base++){

				//総重量
				ll sum_W = 0;
				if(base == 0){

					sum_W = table[i];
				}else{

					sum_W = table[i]-table[base-1];
				}

				int left = 0,right = (int)V.size()-1,mid = (left+right)/2;
				int loc = -1;

				//耐えられない最小のindexを求める

				while(left <= right){

					if(V[mid].value < sum_W){

						loc = mid;
						right = mid-1;
					}else{

						left = mid+1;
					}
					mid = (left+right)/2;
				}

				ll add_len = 0;

				if(loc == -1){ //全ての橋がOK

					add_len = 0;

				}else{

					add_len = V[loc].len;
				}

				//printf("i:%lld base:%lld add_len:%lld sum_W:%lld loc:%d\n",i,base,add_len,sum_W,loc);

				work[i] = max(work[i],work[base]+add_len);
			}
		}
		ans = min(ans,work[N-1]);

	}while(next_permutation(vec.begin(),vec.end()));

	printf("%lld\n",ans);

	return 0;
}
