#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long

//#define debug(x) ;
#define debug(x) cerr << #x << " = " << x << "\n";

ostream& operator<<(ostream& cerr, vector<ll> aux) {
  cerr << "[";
  for (auto e : aux) cerr << e << ' ';
  cerr << "]";
  return cerr;
}

const int maxN = 10;
const int maxM = 100011;
const int inf = 1 << 30;

int n, m, l, v;
int w[maxN], aux[maxN], d[maxN];
vector< pair<int, int> > q;
vector<int> ord;
int ans = inf;

int find_need(int total) {
  int pos = lower_bound(q.begin(), q.end(), mp(total, 0)) - q.begin();
  if (pos == 0) return 0;
  return q[pos - 1].second;
}

int solve() {
  memset(d, 0, sizeof(d));
  for (int i = 1; i < n; i++) {
    int total = 0;

    for (int j = i; j <= n; j++) {
      total += aux[j];
      int need = find_need(total);
      d[j] = max(d[j], d[i] + need);

      if (j == i && need != 0) {
        cout << -1;
        exit(0);
      }
    }
  }

/*
  cerr << "\n\n";
  for (int i = 1; i <= n; i++) {
    cerr << aux[i] << ' ' << d[i] << '\n';
  }
  */

  return d[n];
}

int main()
{
  //freopen("test.in", "r", stdin);

  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) 
    scanf("%d", &w[i]);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &l, &v);
    q.pb(mp(v, -l));
  }

  sort(q.begin(), q.end());
  for (int i = 0; i < q.size(); i++)
    q[i].second = -q[i].second;
  for (int i = 1; i < q.size(); i++) {
    q[i].second = max(q[i].second, q[i - 1].second);
  }

  for (int i = 1; i <= n; i++) 
    ord.pb(i);

  do {
    for (int i = 0; i < n; i++) 
      aux[i + 1] = w[ord[i]];

    ans = min(ans, solve());

  } while (next_permutation(ord.begin(), ord.end()));
 
  cout << ans;

  return 0;
}

/*Lucky_Glass*/
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

typedef long long ll;
const int N=10,M=1e5+10;

int n,m;
int wei[N],id[N];
ll f[N];
pair<int,int> bri[M]; //(limit,length)

inline int Read(int &r){
	int b=1,c=getchar();r=0;
	while(c<'0' || '9'<c) b=c=='-'? -1:b,c=getchar();
	while('0'<=c && c<='9') r=(r<<1)+(r<<3)+(c^'0'),c=getchar();
	return r*=b;
}
int Query(int tot){
	int le=0,ri=m;
	while(le+1<ri){
		int mi=(le+ri)>>1;
		if(bri[mi].first<tot) le=mi;
		else ri=mi;
	}
	if(bri[ri].first<tot) return bri[ri].second;
	return bri[le].second;
}
int main(){
	Read(n),Read(m);
	int minbri=1e8,maxwei=0;
	for(int i=1;i<=n;i++) maxwei=max(maxwei,Read(wei[i])),id[i]=i;
	for(int i=1;i<=m;i++){
		Read(bri[i].second);
		minbri=min(minbri,Read(bri[i].first));
	}
	if(minbri<maxwei){
		printf("-1\n");
		return 0;
	}
	sort(bri+1,bri+1+m);
	for(int i=2;i<=m;i++)
		bri[i].second=max(bri[i].second,bri[i-1].second);
	ll ans=(ll)1e18;
	do{
		for(int i=1;i<=n;i++) f[i]=0;
		for(int i=1;i<=n;i++){
			int tot=wei[id[i]];
			for(int j=i+1;j<=n;j++){
				tot+=wei[id[j]];
				f[j]=max(f[j],f[i]+Query(tot));
			}
		}
		ans=min(ans,f[n]);
	}while(next_permutation(id+1,id+1+n));
	printf("%lld\n",ans);
	return 0;
}