//Let's join Kaede Takagaki Fan Club !!
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
#define int long long
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define a first
#define b second
#define fi first
#define sc second
#define rng(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define all(x) x.begin(),x.end()
#define si(x) (int)(x.size())

#ifdef LOCAL
#define dmp(x) cerr<<__LINE__<<" "<<#x<<" "<<x<<endl
#else
#define dmp(x) void(0)
#endif

template<class t,class u> bool chmax(t&a,u b){if(a<b){a=b;return true;}else return false;}
template<class t,class u> bool chmin(t&a,u b){if(b<a){a=b;return true;}else return false;}

template<class t> using vc=vector<t>;

template<class t,class u>
ostream& operator<<(ostream& os,const pair<t,u>& p){
	return os<<"{"<<p.fi<<","<<p.sc<<"}";
}

template<class t> ostream& operator<<(ostream& os,const vc<t>& v){
	os<<"{";
	for(auto e:v)os<<e<<",";
	return os<<"}";
}

template<class T>
void g(T &a){
	cin >> a;
}
template<class T>
void o(const T &a,bool space=false){
	cout << a << (space?' ':'\n');
}
//ios::sync_with_stdio(false);
const ll mod = 1000000007;//998244353
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
template<class T>
void add(T&a,T b){
	a+=b;
	if(a >= mod) a-=mod;
}
ll modpow(ll x,ll n){
	ll res=1;
	while(n>0){
		if(n&1) res=res*x%mod;
		x=x*x%mod;
		n>>=1;
	}
	return res;
}
int n,m,w[100005];
P pp[100005];
int mx[100005];
int dist[8];
void solve(){
	cin>>n>>m;
	rep(i,n)cin>>w[i];
	rep(i,m)cin>>pp[i].b>>pp[i].a;
	sort(pp, pp+m);
	rep(i, m){
		if(!i) mx[i] = pp[i].b;
		else mx[i] = max(mx[i-1], pp[i].b);
	}
	vc<int>p(n); rep(i,n)p[i]=i;
	ll ans = 1e18;
	do{
		rep(i, n){
		    dist[i] = INF;
		}
		dist[n-1] = 0;
		vc<P>edge[8];
		rep(i, n){
			int W = 0;
			rng(j, i, n){
				W += w[p[j]];
				int v = lower_bound(pp, pp+m, mp(W, (ll)-INF)) - pp;
				v--;
				if(v == -1) v = 0;
				else v = mx[v];
				
				edge[j].pb(mp(i, -v));
			}
		}
		rep(m, n*n+5){
    		rep(i, n){
    		    for(auto a:edge[i]){
    		        if(dist[a.a] > dist[i] + a.b){
    		            dist[a.a] = dist[i] + a.b;
    		            if(m >= n*n) goto bad;
    		        }
    		    }
    		}
		}
		chmin(ans, -dist[0]);
		bad:;
	}while(next_permutation(all(p)));
	if(ans > 5e17) ans = -1;
	cout<<ans<<endl;
}
signed main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout<<fixed<<setprecision(20);
	int t; t = 1; //cin >> t;
	while(t--) solve();
}

#include<bits/stdc++.h>
using namespace std;

typedef long long LL;

const int N=8,M=100000,INF=(1<<30)-1;

int n,m,a[N+9];
struct thing{
  int l,v;
  thing(int L=0,int V=0){l=L;v=V;}
}b[M+9];

bool cmp(const thing &a,const thing &b){return a.v<b.v;}

void into(){
  scanf("%d%d",&n,&m);
  for (int i=1;i<=n;++i)
	scanf("%d",&a[i]);
  for (int i=1;i<=m;++i)
	scanf("%d%d",&b[i].l,&b[i].v);
}

int mx[M+9];

void Get_mx(){
  sort(b+1,b+m+1,cmp);
  mx[0]=0;
  for (int i=1;i<=m;++i) mx[i]=max(mx[i-1],b[i].l);
}

int p[N+9],vis[N+9];
int dp[N+9],ans;

void Get_dp(){
  dp[0]=0;
  for (int i=1;i<=n;++i){
	dp[i]=dp[i-1];
	int sum=p[i];
	for (int j=i-1;j>=1;--j){
	  sum+=p[j];
      dp[i]=max(dp[i],dp[j]+mx[lower_bound(b+1,b+m+1,thing(0,sum),cmp)-b-1]);
	}
  }
  ans=min(ans,dp[n]);
}

void Dfs_ans(int k){
  if (k>n){
	Get_dp();
	return;
  }
  for (int i=1;i<=n;++i)
	if (!vis[i]){
	  p[k]=a[i];
	  vis[i]=1;
	  Dfs_ans(k+1);
	  vis[i]=0;
	}
}

void Get_ans(){
  ans=INF;
  int mx=a[1];
  for (int i=2;i<=n;++i) mx=max(mx,a[i]);
  int mn=b[1].v;
  for (int i=2;i<=m;++i) mn=min(mn,b[i].v);
  if (mx>mn) return;
  Dfs_ans(1);
}

void work(){
  Get_mx();
  Get_ans();
}

void outo(){
  printf("%d\n",ans==INF?-1:ans);
}

int main(){
  into();
  work();
  outo();
  return 0;
}