#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = false;
//---------------------------------//

int main() {
	int N, M;
	cin >> N >> M;
	vector<int> W(N);
	REP(i, N) cin >> W[i];
	vector<int> L(M), V(M);
	REP(i, M) scanf("%d %d", &L[i], &V[i]);
	vector<int> ord(M);
	iota(ALL(ord), 0);
	sort(ALL(ord), [&](int x, int y) { return L[x] < L[y]; });
	vector<pii> dat(M); // min V, L
	dat[M - 1] = {V[ord[M - 1]], L[ord[M - 1]]};
	for (int i = M - 2; i >= 0; --i) dat[i] = {min(dat[i + 1].first, V[ord[i]]), L[ord[i]]};
	
	if (dat[0].first < *max_element(ALL(W))) {
		puts("-1");
		return 0;
	}
	
	int ans = INF;
	ord.resize(N);
	iota(ALL(ord), 0);
	do {
		[&]() -> void {
			vector<int> sumw(N + 1); // [0, i)
			REP(i, N) sumw[i + 1] = sumw[i] + W[ord[i]];
			vector<int> pos(N);
			pos[0] = 0;
			FOR(i, 1, N) {
				REP(j, i) {
					int sw = sumw[i + 1] - sumw[j];
					int idx = lower_bound(ALL(dat), pii{sw, -1}) - dat.begin();
					if (idx == 0) continue;
					--idx;
					chmax(pos[i], pos[j] + dat[idx].second);
				}
			}
			chmin(ans, pos[N - 1] - pos[0]);
		}();
	} while (next_permutation(ALL(ord)));
	
	cout << ans << endl;
}
/*
				author : Piyush Singh
*/
#include <bits/stdc++.h>
using namespace std;

int main() {	
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m;
	cin >> n >> m;
	vector<int> w(n);
	for (int i = 0; i < n; i++) {
		cin >> w[i];
	}
	int mx = *max_element(w.begin(), w.end());
	vector<int> sums(1 << n), mn(1 << n);
	for (int i = 0; i < (1 << n); i++) {
		int x = 0;
		for (int j = 0; j < n; j++) {
			if (i & (1 << j)) {
				x += w[j];
			}
		}
		sums[i] = x;
	}
	for (int i = 0; i < m; i++) {
		int l, v;
		cin >> l >> v;
		if (v < mx) {
			cout << -1 << '\n';
			return 0;
		} 
		for (int j = 0; j < (1 << n); j++) {
			if (sums[j] > v) {
				mn[j] = max(mn[j], 	l);
			}
		}
	}
	int ans = (int) 1e9;
	vector<int> per(n);
	iota(per.begin(), per.end(), 0);
	do {
		vector<int> pos(n);
		for (int i = 0; i < n; i++) {
			int s = 1 << per[i];
			for (int j = i - 1; j >= 0; j--) {
				s |= 1 << per[j];
				pos[i] = max(pos[i], pos[j] + mn[s]);
			}
		}
		ans = min(ans, pos[n - 1]);
	} while (next_permutation(per.begin(), per.end()));
	cout << ans << '\n';
	return 0;
}