#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int INF = 1e9;

struct part {
    int v, l;
    part(int v=0, int l=0): v(v), l(l) {}
};

int main() {
    // 全探索、重さでソート、最長路、二分探索
    int N, M;
    cin >> N >> M;
    vector<int> W(N);
    rep(i, N) cin >> W[i];
    sort(W.begin(), W.end());
    vector<part> LV(M);
    int maxV = 0, minV = 1e9;
    rep(i, M) {
        int l, v;
        cin >> l >> v;
        maxV = max(maxV, v);
        minV = min(minV, v);         
        LV[i].v = v;
        LV[i].l = l;        
    }
    if (W[N-1] > minV) {
        cout << -1 << '\n';
        return 0;
    }
    sort(LV.begin(), LV.end(), [&] (const part& x, const part& y) { return x.v < y.v; });
    map<int, ll> mp;
    rep(i, M) {
        int key = LV[i].v;
        int value = LV[i].l;
        if (mp[key] < value) {
            mp[key] = value;
        }
    }
    int maxL = 0;
    for (auto &p : mp) {
        if (p.second > maxL) {
            maxL = p.second;
        }
        p.second = maxL;
    }
    mp[INF] = maxL;
    vector<int> pos(N);
    rep(i, N) pos[i] = i;
    ll ans = 1e16;
    do {
        vector<P> ws(N);
        rep(i, N) ws[i].first = W[pos[i]];
        vector<vector<ll>> dist(N, vector<ll> (N));
        rep(i, N) for (int j = i+1; j < N; j++) {
            // iからjまでの重さが十分の距離があるか
            int temp = 0;
            for (int k = i; k <= j; k++) {
                temp += ws[k].first;
            }
            if (temp <= minV) continue;
            auto it = mp.lower_bound(temp);
            if (it == mp.begin()) continue;
            it--;
            dist[i][j] = it -> second;
        }
        vector<ll> dp(N);
        rep(i, N) for (int j = i+1; j < N; j++) {
            dp[j] = max(dp[j], dp[i] + dist[i][j]);            
        }
        ans = min(ans, dp[N-1]);
    } while (next_permutation(pos.begin(), pos.end()));
    cout << ans << '\n';
    return 0;
}
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;
using ui = unsigned int;
using ull = unsigned long long;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vui = vector<ui>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
template <typename T>
using vv = vector<vector<T>>;
template <typename T>
using vvv = vector<vector<vector<T>>>;

int main()
{
	int N, M;
	cin >> N >> M;
	vi w(N);
	auto maxW = 0;
	for (auto& i : w)
	{
		cin >> i;
		maxW = max(maxW, i);
	}
	vector<pair<int, int>> list(M);
	auto valid = true;
	for (auto i = 0; i < M; ++i)
	{
		cin >> list[i].second >> list[i].first;
		if (list[i].first < maxW)
		{
			valid = false;
		}
	}

	auto ans = -1ll;

	if (valid)
	{
		ans = LLONG_MAX;

		sort(list.begin(), list.end());
		vl v(M);
		vl maxL(M + 1);
		for (auto i = 0; i < M; ++i)
		{
			v[i] = list[i].first;
			maxL[i + 1] = max(maxL[i], (ll)list[i].second);
		}

		vi index(N);
		for (auto i = 0; i < N; ++i)
		{
			index[i] = i;
		}

		auto calc = [&](int l, int r)
		{
			auto sumW = 0ll;
			for (auto i = l; i <= r; ++i)
			{
				sumW += w[index[i]];
			}
			auto indexL = lower_bound(v.begin(), v.end(), sumW) - v.begin();
			return maxL[indexL];
		};

		do
		{
			vl dp(N, 0);
			for (auto i = 0; i < N - 1; ++i)
			{
				for (auto j = i + 1; j < N; ++j)
				{
					dp[j] = max(dp[j], dp[i] + calc(i, j));
				}
			}
			ans = min(ans, dp[N - 1]);
		} while (next_permutation(index.begin(), index.end()));
	}

	cout << ans << endl;

	return 0;
}