#ifdef __GNUC__
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#endif

#include <algorithm>
#include <cmath>
#include <cstring>
#include <cctype>
#include <iostream>
#include <sstream>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <vector>

using namespace std;

typedef long long LL;
typedef long double LD;
typedef pair<LL, LL> II;
typedef pair<LL, II> III;
typedef priority_queue<III, vector<III>, greater<>> Queue;
static const LL INF = 1LL << 60;

void solve(long long N, long long M, std::vector<long long>& w, std::vector<long long>& l, std::vector<long long>& v) {
	LL max_w = *max_element(w.begin(), w.end());
	LL min_allow = *min_element(v.begin(), v.end());
	if (max_w > min_allow) {
		cout << -1 << endl;
		return;
	}
	//	if (min_allow >= accumulate(w.begin(), w.end(), 0LL)) {
	//		cout << 0 << endl;
	//		return;
	//	}
	vector<II> vv;
	for (int i = 0; i < M; ++i) {
		vv.emplace_back(II(l[i], v[i]));
	}
	sort(vv.begin(), vv.end());
	map<LL, LL> m;
	m[0] = 0;
	LL mn = INF;
	for (LL i = M - 1; i >= 0; --i) {
		if (vv[i].second < mn) {
			mn = vv[i].second;
			m[mn] = vv[i].first;
		}
	}

	sort(w.rbegin(), w.rend());
	vector<int> seq(N);
	iota(seq.begin(), seq.end(), 0);

	LL ans = INF;
	do {
		vector<vector<LL>> dist(N, vector<LL>(N));
		vector<LL> pos(N);
		for (LL i = 1; i < N; ++i) {
			LL tot_w = w[seq[i]];
			for (LL j = i - 1; j >= 0; --j) {
				tot_w += w[seq[j]];
				auto x = m.lower_bound(tot_w);
				if (x == m.end()) --x;
				if (tot_w <= x->first) --x;
				dist[i][j] = dist[j][i] = -x->second;
			}
		}

		// Bellman-Ford
		vector<LL> costs(N);
		costs[0] = 0;
		for (int k = 0; k < N; ++k) {
			bool changed = false;
			for (int i = 0; i < N; ++i) {
				for (int j = i + 1; j < N; ++j) {
					LL cost = costs[i] + dist[i][j];
					if (costs[j] > cost) {
						changed = true;
						costs[j] = cost;
					}
				}
			}
			if (!changed) break;
		}
		ans = min(ans, -costs[N - 1]);
	} while (next_permutation(seq.begin() + 1, seq.end()));

	cout << ans << endl;
}

int main() {
	long long N, M;
	std::cin >> N >> M;
	std::vector<long long> w(N), l(M), v(M);
	for (int i = 0; i < N; i++) {
		std::cin >> w[i];
	}
	for (int i = 0; i < M; i++) {
		std::cin >> l[i] >> v[i];
	}
	solve(N, M, w, l, v);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
// --------------------------------------------------------
template<class T> bool chmax(T& a, const T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, const T b) { if (b < a) { a = b; return 1; } return 0; }
#define FOR(i,l,r) for (ll i = (l); i < (r); ++i)
#define RFOR(i,l,r) for (ll i = (r)-1; (l) <= i; --i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define MIN(c) *min_element(ALL(c))
#define MAX(c) *max_element(ALL(c))
#define SUMLL(c) accumulate(ALL(c), 0LL)
#define COUNT(c,v) count(ALL(c),(v))
#define SZ(c) ((ll)(c).size())
#define BIT(b,i) (((b)>>(i)) & 1)
#define PCNT(b) __builtin_popcountll(b)
#define CIN(c) cin >> (c)
#define COUT(c) cout << (c) << '\n'
#define debug(x) cerr << "l." << __LINE__ << " : " << #x << " = " << (x) << '\n'
ll llceil(ll a, ll b) { return (a + b - 1) / b; }
string toupper(const string& S) { string T(S); REP(i,SZ(T)) T[i] = toupper(T[i]); return T; }
string tolower(const string& S) { string T(S); REP(i,SZ(T)) T[i] = tolower(T[i]); return T; }
using P = pair<ll,ll>;
using VP = vector<P>;
using VVP = vector<VP>;
using VS = vector<string>;
using VVS = vector<VS>;
using VLL = vector<ll>;
using VVLL = vector<VLL>;
using VVVLL = vector<VVLL>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VVVB = vector<VVB>;
using VD = vector<double>;
using VVD = vector<VD>;
using VVVD = vector<VVD>;
using VLD = vector<ld>;
using VVLD = vector<VLD>;
using VVVLD = vector<VVLD>;
static const double EPS = 1e-10;
static const double PI  = acos(-1.0);
static const ll MOD = 1000000007;
// static const ll MOD = 998244353;
static const ll INF = (1LL << 62) - 1;  // 4611686018427387904 - 1
// --------------------------------------------------------
// #include <atcoder/all>
// using namespace atcoder;

// Editorial AC

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

    ll N, M; cin >> N >> M;
    VLL w(N); REP(i,N) cin >> w[i];
    VLL l(M),v(M); REP(i,M) cin >> l[i] >> v[i];

    if (MAX(w) > MIN(v)) { COUT(-1); return 0; }

    VLL X(1<<N);
    REP(S,1<<N) if (PCNT(S) >= 2) {
        ll W = 0;
        REP(i,N) if (BIT(S,i)) W += w[i];
        REP(i,M) if (v[i] < W) chmax(X[S], l[i]);
    }

    ll ans = INF;
    VLL A(N); iota(ALL(A),0);
    VLL dp(N);
    do {
        fill(ALL(dp), 0);
        REP(s,N-1) {
            ll u1 = A[s];
            ll S = (1<<u1);
            FOR(t,s+1,N) {
                ll u2 = A[t];
                S |= (1<<u2);
                chmax(dp[t], dp[s] + X[S]);
            }
        }
        chmin(ans, dp[N-1]);
    } while (next_permutation(ALL(A)));
    assert(ans != INF);

    COUT(ans);

    return 0;
}
