#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
using ll = long long;
const ll INF = 1e17;

int main(){
  int n, m;
  cin >> n >> m;
  ll w[n], l[m], v[m], a[n];
  rep(i,n) a[i] = i;
  rep(i,n) cin >> w[i];
  rep(i,m) cin >> l[i] >> v[i];
  rep(i,n) {
    rep(j,m) {
      if(w[i] > v[j]) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  vector<ll> d(1<<n);
  rep(i,1<<n) {
    ll weight = 0, dist = 0;
    rep(j,n) if(i & (1<<j)) weight += w[j];
    rep(j,m) if(weight > v[j]) dist = max(dist,l[j]);
    d[i] = dist;
  }
  ll ans = INF;
  do {
    vector<ll> dp(n);
    for(int i = 1; i < n; i++) {
      rep(j,i) {
        int id = 0;
        for(int k = j; k <= i; k++) id |= (1<<a[k]);
        dp[i] = max(dp[i],dp[j]+d[id]); 
      }
    }
    ans = min(ans,dp[n-1]);
  } while(next_permutation(a,a+n));
  cout << ans << endl;
  return 0;
}

/**
 *   @FileName	c.cpp
 *   @Author	kanpurin
 *   @Created	2020.10.11 23:04:57
**/

#include "bits/stdc++.h" 
using namespace std; 
typedef long long ll;



template<typename T>
struct Bellman_Ford {
private:
    struct edge { int to; T cost; };
    int V; 
    vector<vector<edge>> G;
    vector<T> d;
public:
    const T inf = numeric_limits<T>::max();
    Bellman_Ford(int V) : V(V){
        G.resize(V);
        d.resize(V);
    }
    
    void add_edge(int from, int to, T cost) {
        G[from].push_back({to,cost});
    }
    
    
    bool build(int s) {
        d.assign(V,inf);
        d[s] = 0;
        for (int i = 0; i < V; i++) {
            for (int j = 0; j < V; j++) {
                for (edge &e : G[j]) {
                    if (d[j] != inf && d[j] + e.cost < d[e.to]) {
                        d[e.to] = d[j] + e.cost;
                        if (i == V - 1) {
                            return false;
                        }
                    }
                }
            }
        }
        /*
        REP(i, V) {
            cout << s << " -> " << i << " = " << d[i] << endl;
        }
        */
        return true;
    }
    
    
    T dist(int v) {
        return d[v];
    }
};
int main() {
    int n,m;cin >> n >> m;
    vector<int> w(n);
    int max_w = 0;
    for (int i = 0; i < n; i++) {
        cin >> w[i];
        max_w = max(max_w,w[i]);
    }
    sort(w.begin(), w.end());
    vector<pair<int,int>> p(m);
    for (int i = 0; i < m; i++) {
        cin >> p[i].second >> p[i].first;
        if (p[i].first < max_w) {
            cout << -1 << endl;
            return 0;
        }
    }
    sort(p.begin(), p.end());
    for (int i = 1; i < m; i++) {
        p[i].second = max(p[i].second,p[i-1].second);
    }
    constexpr long long LLINF = 1e18 + 1;
    ll ans = LLINF;
    do {
        Bellman_Ford<ll> g(n);
        for (int i = 0; i < n-1; i++) {
            int sum = w[i];
            for (int j = i+1; j < n; j++) {
                sum += w[j];
                auto t = lower_bound(p.begin(), p.end(), make_pair(sum,-1));
                if (t == p.begin()) {
                    g.add_edge(i,j,0);
                }
                else {
                    t--;
                    g.add_edge(i,j,-(*t).second);
                }
            }
        }
        g.build(0);
        ans = min(ans,-g.dist(n-1));
    } while(next_permutation(w.begin(), w.end()));
    cout << ans << endl;
    return 0;
}