#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ll mod2 = 998244353;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m; cin >> n >> m;
  vector<ll> W(n); rep(i, n) cin >> W[i];
  vector<pair<ll, ll>> LV(m);
  ll minV = longinf;
  rep(i, m) {
    cin >> LV[i].first >> LV[i].second;
    chmin(minV, LV[i].second);
  }
  sort(all(LV), [&](pair<ll, ll> p1, pair<ll, ll> p2) {
    return p1.second < p2.second;
  });
  vector<ll> L(m), V(m);
  rep(i, m) {
    L[i] = LV[i].first;
    V[i] = LV[i].second;
  }
  vector<ll> mx(m+1);
  rep(i, m) mx[i+1] = max(mx[i], L[i]);
  rep(i, n) {
    if(W[i] > minV) {
      cout << -1 << endk;
      return 0;
    }
  }
  vector<int> id(n); rep(i, n) id[i] = i;
  ll ans = longinf;
  auto solve = [&](vector<int> id) {
    vector<ll> sum(n+1); rep(i, n) sum[i+1] = sum[i]+W[id[i]];
    vector<vector<ll>> d(n, vector<ll>(n));
    rep(i, n) {
      REP(j, i+1, n) {
        int k = upper_bound(all(V), sum[j+1]-sum[i]-1)-begin(V);
        d[i][j] = mx[k];
      }
    }
    vector<ll> D(n);
    rep(i, n) {
      REP(j, i+1, n) {
        chmax(D[j], D[i]+d[i][j]);
      }
    }
    chmin(ans, D[n-1]);
  };
  do {
    solve(id);
  } while(next_permutation(all(id)));
  cout << ans << endk;
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

const int BS=524288;

int CNT,rc;
char inb[BS];

inline char gchar(void){
    if(CNT%BS==0){
        CNT=0;
        rc=fread(inb,1,BS,stdin);
    }
    return CNT<rc?inb[CNT++]:0;
}

inline int _readint(int *ptr){
    int n=0,c=0;
    *ptr=0;
    while(1){
        char read=gchar();
        if(read>='0'&&read<='9')read-='0',n*=10,n+=read;
        else{*ptr=n;return n==0?0:!c;}
        c++;
    }
    *ptr=n;
    return 0;
}

inline int readint(void){int ptr;while(_readint(&ptr));return ptr;}

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n,m; 
	// cin >> n >> m;
	n=readint(); m=readint();
	vector<ll> w(n);
	for(int i=0;i<n;i++){
		// cin >> w[i];
		w[i]=readint();
	}
	sort(w.rbegin(), w.rend());
	vector<ll> l(m),v(m);
	for(int i=0;i<m;i++){
		// cin >> l[i] >> v[i];
		l[i]=readint(); v[i]=readint();
	}
	for(int i=0;i<m;i++){
		if(v[i]<w[0]){
			printf("-1\n");
			return 0;
		}
	}
	ll res=1e18;
	vector<int> p(n-2);
	for(int i=0;i<n-2;i++){
		p[i]=i+2;
	}
	do{
		vector<ll> vec(n,0);
		vector<int> pp(n);
		pp[0]=0;
		for(int i=0;i<n-2;i++){
			pp[i+1]=p[i];
		}
		pp[n-1]=1;
		for(int i=1;i<n;i++){
			ll mi=vec[i-1];
			for(int j=0;j<m;j++){
				ll sum=w[pp[i]];
				for(int k=i-1;k>=0;k--){
					if(abs(mi-vec[k])<l[j]){
						// cout << i << " " << k << " " << mi << endl;
						sum+=w[pp[k]];
						// cout << sum << endl;
						if(sum>v[j]){
							mi=vec[k]+l[j];
							break;
						}
					}
					else break;
				}
			}
			vec[i]=mi;
		}
		res=(res>vec[n-1]?vec[n-1]:res);
		// res=min(res,vec[n-1]);
	}while(next_permutation(p.begin(), p.end()));
	cout << res << endl;
}