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

using ll = long long;
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define POPCOUNT(x) __builtin_popcount(x)
template <typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template <typename T> void chmax(T &a, const T &b) { a = max(a, b); }

const ll INF = 1LL << 60;

struct FastIO {
    FastIO() {
        cin.tie(0);
        ios::sync_with_stdio(0);
    }
} fastiofastio;

const ll MOD = 1e9 + 7;

int main() {
    int N, M;
    cin >> N >> M;
    vector<ll> w(N);
    REP(i, N) cin >> w[i];
    vector<ll> l(M), v(M);
    REP(i, M) cin >> l[i] >> v[i];
    vector<ll> vec = v;
    sort(ALL(vec));
    vec.erase(unique(ALL(vec)), vec.end());
    int sz = vec.size();
    vector<ll> mi(sz + 1);
    REP(i, M) {
        int idx = lower_bound(ALL(vec), v[i]) - vec.begin();
        chmax(mi[idx], l[i]);
    }
    REP(i, sz) chmax(mi[i + 1], mi[i]);
    vector<int> perm(N);
    iota(ALL(perm), 0);
    ll ans = INF;
    do {
        vector<ll> pos(N);
        vector<vector<PII>> G(N, vector<PII>());
        bool NG = 0;
        REP(i, N) {
            ll sum = 0;
            FOR(j, i, N) {
                sum += w[perm[j]];
                int idx = lower_bound(ALL(vec), sum) - vec.begin();
                if (idx > 0) {
                    if (i == j) {
                        cout << -1 << endl;
                        return 0;
                    }
                    G[i].emplace_back(j, mi[idx - 1]);
                }
            }
        }
        REP(i, N) {
            for (auto [to, len] : G[i]) {
                chmax(pos[to], pos[i] + len);
            }
        }
        chmin(ans, pos[N - 1]);
    } while (next_permutation(ALL(perm)));
    cout << ans << endl;
}
#include<bits/stdc++.h>
#define llinf 4154118101919364364

using namespace std;

long long n,m;
long long w[32],l[131072],v[131072];
long long res=llinf;
long long sigw[1024]={0};
map<long long,long long> mp;

long long find(long long wei){
  if(mp[wei]!=-1){return mp[wei];}
  long long d=0;
  for(int i=0;i<m;i++){
    if(v[i]<wei){d=max(l[i],d);}
  }
  mp[wei]=d;
  return mp[wei];
}

long long p[16],d[16];
void rep(long long fl,long long cnt){
  //cerr << fl << ' ' << d[cnt-1] << '\n';
  if(cnt==n){
    res=min(d[n-1],res);
    return;
  }
  for(int i=0;i<n;i++){
    if(!(fl&(1ll<<i))){continue;}
    p[cnt]=i;
    d[cnt]=0;
    long long cw=0;
    for(int j=0;j<cnt;j++){
      cw+=w[p[j]];
    }
    cw+=w[i];
    for(int j=0;j<cnt;j++){
      //cout << fl << ' ' << j << ' ' << cw  << ' ' << find(cw)<< '\n';
      d[cnt]=max(d[j]+find(cw),d[cnt]);
      cw-=w[p[j]];
    }
    rep(fl^(1ll<<i),cnt+1);
  }
  return;
}

int main(){
  long long mr=0;
  scanf("%lld%lld",&n,&m);
  for(int i=0;i<n;i++){
    scanf("%lld",&w[i]);
    mr=max(w[i],mr);
  }
  for(int i=0;i<m;i++){
    scanf("%lld%lld",&l[i],&v[i]);
    if(v[i]<mr){puts("-1");return 0;}
  }
  mp[0]=0;
  for(int i=1;i<(1ll<<n);i++){
    for(int j=0;j<n;j++){
      if(i&(1ll<<j)){sigw[i]+=w[j];}
    }
    mp[sigw[i]]=-1;
    //cout << sigw[i] << '\n';
  }
  rep((1ll<<n)-1,0);
  printf("%lld\n",res);
  return 0;
}
