#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
int main(){
  int N, M;
  cin >> N >> M;
  vector<int> w(N);
  for (int i = 0; i < N; i++){
    cin >> w[i];
  }
  vector<int> l(M), v(M);
  for (int i = 0; i < M; i++){
    cin >> l[i] >> v[i];
  }
  vector<pair<int, int>> P(M + 1);
  for (int i = 0; i < M; i++){
    P[i] = make_pair(v[i], l[i]);
  }
  P[M] = make_pair(0, 0);
  sort(P.begin(), P.end());
  for (int i = 0; i < M; i++){
    P[i + 1].second = max(P[i + 1].second, P[i].second);
  }
  int wmax = *max_element(w.begin(), w.end());
  int vmin = *min_element(v.begin(), v.end());
  if (wmax > vmin){
    cout << -1 << endl;
  } else {
    long long ans = INF;
    vector<int> p(N);
    for (int i = 0; i < N; i++){
      p[i] = i;
    }
    while (1){
      vector<long long> w2(N);
      for (int i = 0; i < N; i++){
        w2[i] = w[p[i]];
      }
      vector<long long> S(N + 1);
      S[0] = 0;
      for (int i = 0; i < N; i++){
        S[i + 1] = S[i] + w2[i];
      }
      vector<long long> x(N);
      x[0] = 0;
      for (int i = 1; i < N; i++){
        long long minx = x[i - 1];
        for (int j = 0; j < i; j++){
          int wsum = S[i + 1] - S[j];
          auto itr = lower_bound(P.begin(), P.end(), make_pair(wsum, -INF)) - 1;
          long long d = (*itr).second;
          minx = max(minx, x[j] + d);
        }
        x[i] = minx;
      }
      ans = min(ans, x[N - 1]);
      if (!next_permutation(p.begin(), p.end())){
        break;
      }
    }
    cout << ans << endl;
  }
}
#include <bits/stdc++.h>
//#include <atcoder/all>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define popcount __builtin_popcount
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
template <class T>
inline bool chmin(T &a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}

ll gcd(ll n, ll m)
{
	ll tmp;
	while (m != 0)
	{
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m)
{
	return abs(n) / gcd(n, m) * abs(m); //gl=xy
}

using namespace std;
//using namespace atcoder;

template<typename T>
struct edge{
  int to;
  T cost;
  edge(int to,T cost):to(to),cost(cost){}
};


template<typename T>
vector<T> dijkstra(vector<vector<edge<T>>> &g,int s){//sは始点
  const auto INFTY=numeric_limits<T>::max();//2回以上使うときはオーバーフローに気をつける(INFTYのときはif文で弾くなど)
  vector<T>dist(g.size(),INFTY);
  using P=pair<T,int>;//firstは最短距離,secondは頂点の番号
  priority_queue<P,vector<P>,greater<P>>pq;
  dist[s]=0;
  pq.emplace(dist[s],s);

  while(!pq.empty()){
    auto x=pq.top();pq.pop();
    int v=x.second;
    if(dist[v]<x.first)continue;//最短距離でなければ飛ばす
    for(auto e:g[v]){
      if(dist[e.to]>dist[v]+e.cost){
        dist[e.to]=dist[v]+e.cost;
        pq.emplace(dist[e.to],e.to);
      }
    }
  }
  return dist;
}

void solve(){
	int n,m;
	cin>>n>>m;
	ll sum=0;
	vector<ll>w(n);
	rep(i,n)cin>>w[i],sum+=w[i];
	sort(all(w));
	vector<pair<ll,ll>>p(m);
	ll minv=INF;
	rep(i,m){
		cin>>p[i].second>>p[i].first;
		chmin(minv,p[i].first);
	}
	if(minv<w.back()){
		cout<<-1<<"\n";
		return;
	}
	sort(all(p));
	vector<ll>v(m);
	rep(i,m){
		v[i]=p[i].first;
	}
	vector<ll>dis(m);
	ll maxdis=0;
	rep(i,m){
		chmax(maxdis,p[i].second);
		dis[i]=maxdis;
	}
	ll ans=INF;
	do{
		vector<ll>dp(n);
		rep(i,n-1){
			ll weight=w[i];
			REP(j,i+1,n){
				weight+=w[j];
				auto itr=lower_bound(all(v),weight);
				if(itr!=v.begin()){
					chmax(dp[j],dp[i]+dis[prev(itr)-v.begin()]);
				}
			}
		}
		chmin(ans,dp[n-1]);
	}while(next_permutation(all(w)));
	cout<<ans;
}

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