#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iomanip>
#include <functional>
#include <bitset>
#include <limits>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <random>

#ifdef DEBUG
#include "library/Utility/debug.cpp"
#else
#define debug(...)
#endif

#define rep(i,n) for(int i=0;i<(n);++i)
#define EL '\n'
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using lnt = long long;
struct FIO{FIO(){std::cin.tie(0);std::ios_base::sync_with_stdio(0);std::cout<<std::fixed<<std::setprecision(15);}}fIO;
template<typename T> using V = std::vector<T>;
template<typename T> void fill(V<T>&v) { for(T&e:v) std::cin >> e; }
/*-*/

int main() {
	int n,m;
	std::cin >> n >> m;
	V<lnt> w(n);
	fill(w);
	std::map<lnt,lnt> map;
	lnt minload=1e18;
	rep(i,m) {
		lnt a,b;
		std::cin >> a >> b;
		map[b]=std::max(map[b],a);
		minload=std::min(minload,b);
	}
	rep(i,n) {
		if(w[i]>minload) {
			print(-1);
			return 0;
		}
	}
	V<std::pair<lnt,lnt> > v;
	v.emplace_back(0,0);
	for(auto e:map) v.emplace_back(e);
	{
		lnt max=0;
		int k=v.size();
		rep(i,k) {
			max=std::max(max,v[i].second);
			v[i].second=max;
		}
	}
	V<int> p(n);
	std::iota(all(p),0);
	lnt min=1e18;
	std::sort(all(w));
	do {
		V<V<std::pair<lnt,lnt> > > g(n);
		V<lnt> a(n);
		rep(i,n) a[i]=w[p[i]];
		V<lnt> ac(n+1,0);
		rep(i,n) ac[i+1]=ac[i]+a[i];
		rep(i,n) {
			for(int j=i+1;j<n;j++) {
				lnt x=ac[j+1]-ac[i];
				int l=-1,r=v.size();
				while(r-l>1) {
					int o=(l+r)>>1;
					if(v[o].first<x) l=o;
					else r=o;
				}
				g[i].emplace_back(j,v[l].second);
			}
		}
		auto dfs=[&](auto f, int i) -> lnt {
			lnt max=0;
			for(auto to:g[i]) {
				max=std::max(max,f(f,to.first)+to.second);
			}
			return max;
		};
		lnt x=dfs(dfs,0);
		min=std::min(min,x);
	} while(std::next_permutation(all(p)));
	print(min);
}

#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }

long long solve() {
    int N, M;
    cin >> N >> M;
    vector<long long> w(N);
    long long maxW = 0;
    for (int i = 0; i < N; ++i) {
        cin >> w[i];
        chmax(maxW, w[i]);
    }
    vector<long long> l(M), v(M);
    for (int j = 0; j < M; ++j) {
        cin >> l[j] >> v[j];
        if (v[j] < maxW) return -1;
    }

    // 前処理
    vector<long long> dist(1<<N, 0);
    for (int bit = 0; bit < (1<<N); ++bit) {
        long long W = 0;
        for (int i = 0; i < N; ++i) {
            if (bit & (1<<i)) W += w[i];
        }
        for (int j = 0; j < M; ++j) {
            if (v[j] < W) {
                chmax(dist[bit], l[j]);
            }
        }
    }

    // DP
    long long res = 1LL<<60;
    vector<int> ids(N);
    iota(ids.begin(), ids.end(), 0);
    do {
        //COUT(ids);
        vector<long long> dp(N, 0);
        for (int i = 1; i < N; ++i) {
            int bit = (1<<ids[i]);
            for (int j = i-1; j >= 0; --j) {
                bit |= (1<<ids[j]);
                chmax(dp[i], dp[j] + dist[bit]);
            }
            //cout << i << ": " << ids[i] << ", " << dp[i] << endl;
        }
        chmin(res, dp[N-1]);
    } while (next_permutation(ids.begin(), ids.end()));
    return res;
}

int main() {
    cout << solve() << endl;
}