//#pragma GCC optimize ("O2")
//#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;

#include<cstdio>
#include<cstring>
#include<algorithm>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

//おそそう

const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	if ((tmp & ma0) ^ ma0) {
		int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
		tmp = tmp << dig & ma1;
		tmp = tmp * 10 + (tmp >> 8) & ma2;
		tmp = tmp * 100 + (tmp >> 16) & ma3;
		tmp = tmp * 10000 + (tmp >> 32) & ma4;
		ci += (72 - dig >> 3);
	}
	else {
		tmp = tmp & ma1;
		tmp = tmp * 10 + (tmp >> 8) & ma2;
		tmp = tmp * 100 + (tmp >> 16) & ma3;
		tmp = tmp * 10000 + (tmp >> 32) & ma4;
		ci += 8;
		if (*ci++ == '0') {
			tmp = tmp * 10;
			ci++;
		}
	}
	return tmp;
}
void pakuri_sort(int N, ll A[]) {
	const int b = 8;
	ll tmp[100001];
	rep(k, 4) {
		int kazu[1 << b] = {}, kazu2[1 << b] = {};
		rep(i, N) kazu[A[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu[i + 1] += kazu[i];
		for (int i = N - 1; i >= 0; i--) tmp[--kazu[A[i] >> k * b & ((1 << b) - 1)]] = A[i];
		k++;
		rep(i, N) kazu2[tmp[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu2[i + 1] += kazu2[i];
		for (int i = N - 1; i >= 0; i--) A[--kazu2[tmp[i] >> k * b & ((1 << b) - 1)]] = tmp[i];
	}
}
ll li[300];
int li2[300];

int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);


	int N = getint(), M = getint();
	int w[8];
	rep(i, N) w[i] = getint();

	ll lv[100001];
	rep(i, M) {
		ll l = getint();
		int v = getint();
		lv[i] = l << 32 | v;
	}
	pakuri_sort(M, lv);
	lv[M] = 1000000001ll;

	rep(i, 1 << N) {
		rep(j, N) if (i >> j & 1) li[i] += w[j];
		li[i] = li[i] << 30 | i;
	}
	sort(li, li + (1 << N));
	int saidai = 0;
	int k = 0;
	rep(i, 1 << N) {
		while ((lv[k] & (1 << 30) - 1) < li[i] >> 30) {
			if (saidai < lv[k] >> 32) saidai = lv[k] >> 32;
			k++;
		}
		li[i] = ll(saidai) << 30 | (li[i] & (1 << 30) - 1);
	}
	rep(i, 1 << N) li2[li[i] & (1 << 30) - 1] = li[i] >> 30;

	rep(i, N) {
		if (w[i] > (lv[0] & (1 << 30) - 1)) {
			printf("-1");
			return 0;
		}
	}
	int P[8];
	rep(i, N) P[i] = i;

	int kotae = 1e9;
	do {
		int tmp[8] = {};
		rep(p, N - 1) {
			int omosa = 1 << P[p];
			for (int q = p + 1; q < N; q++) {
				omosa |= 1 << P[q];
				int kari = tmp[p] + li2[omosa];
				if (tmp[q] < kari) tmp[q] = kari;
			}
		}
		if (kotae > tmp[N - 1]) kotae = tmp[N - 1];
		
	} while (next_permutation(P, P + N));

	printf("%d\n", kotae);

	Would you please return 0;
}
#include<bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define time_taken_start int begtime = clock();
#define time_taken_end int endtime = clock(); \
cerr << "\n\n" << "Time elapsed: " << \
(endtime - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n"; \
return 0;
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define mod 1000000007
#define inf 100000000000000007
#define eps 0.000000000001
#define pi acosl(-1)
#define pdd pair<ld,ld>
#define pll pair<ll,ll>
#define ff first
#define ss second
#define vpl vector<pll>
#define vll vector<ll>
#define mseti multiset <ll>
#define msetd multiset <ll,greater<ll>>
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound 
#define stp fixed<<setprecision(20)
#define endl '\n'
vll v;
pll p[100009];
ll n,m;
ll md;
ll dis(ll x)
{
    ll l=0,u=m-1,mid;
    ll ans=md;
    while(l<=u)
    {
        mid=(l+u)/2;
        if(p[mid].ff>=x)
        {
            u=mid-1;
        }
        else
        {
            l=mid+1;
            ans=p[mid].ss;
        }
    }
    if(u==-1)
        ans=0;
    return ans;
}
ll check()
{
    ll a[n+1];
    a[n]=0;
    ll pre[n+1];
    pre[0]=0;
    for(ll i=0;i<n;i++)
    {
        a[i]=0;
        pre[i+1]=v[i]+pre[i];
    }
    ll sum;
    for(ll i=2;i<=n;i++)
    {
        sum=0;
        for(ll j=i-1;j>0;j--)
        {
            ll x=pre[i]-pre[j-1];
            a[i]=max(a[i],dis(x)-sum);
            //cout<<i<<' '<<j<<' '<<x<<' '<<dis(x)<<' '<<a[j]<<' '<<sum<<endl;
            sum+=a[j];
        }
    }
    sum=0;
    for(ll i=0;i<=n;i++)
        sum+=a[i];
    return sum;
}
void solve()
{
    cin>>n>>m;
    ll x,y;
    ll cm=0,bm=inf;
    for(ll i=0;i<n;i++)
    {
        cin>>x;
        v.pb(x);
        cm=max(cm,x);
    }
    for(ll i=0;i<m;i++)
    {
        cin>>p[i].ss>>p[i].ff;
        bm=min(bm,p[i].ff);
        md=max(md,p[i].ss);
    }
    if(cm>bm)
    {
        cout<<-1;
        return;
    }
    sort(p,p+m);
    for(ll i=1;i<m;i++)
    {
        p[i].ss=max(p[i].ss,p[i-1].ss);
    }
    ll ans=inf;
    sort(v.begin(),v.end());
    do{
        ans=min(check(),ans);
    }while(next_permutation(v.begin(),v.end()));
    cout<<ans;
}
int main()
{
    FAST
    #ifdef ayk_16
    freopen("input.txt","rt",stdin);
    freopen("output.txt","wt",stdout);
    #endif
    time_taken_start
    ll t=1;
    //cin>>t;
    for(ll i=0;i<t;i++)
    {
        //cout<<"Case #"<<i+1<<": ";
        solve();
    }
    time_taken_end
}