#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll MOD = 1000000007;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> w(n);
  vector<int> sums(1 << n), mn(1 << n);
  REP(i, n) cin >> w[i];
  int mx = *max_element(w.begin(), w.end());
  for (int s = 0; s < (1 << n); s++) {
    int x = 0;
    REP(j, n) if (s >> j & 1) x += w[j];
    sums[s] = x;
  }
  REP(i, m) {
    int l, v;
    cin >> l >> v;
    if (v < mx) {
      cout << -1 << endl;
      return 0;
    }
    for (int s = 0; s < (1 << n); ++s)
      if (sums[s] > v) mn[s] = max(mn[s], l);
  }
  int ans = 1e9;
  vector<int> perm(n);
  iota(perm.begin(), perm.end(), 0);
  do {
    vector<int> pos(n);
    REP(i, n) {
      int s = 1 << perm[i];
      for (int j = i - 1; j >= 0; j--) {
        s |= 1 << perm[j];
        pos[i] = max(pos[i], pos[j] + mn[s]);
      }
    }
    ans = min(ans, pos[n - 1]);
  } while (next_permutation(perm.begin(), perm.end()));
  cout << ans << endl;
  return 0;
}
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
int main(){
  int N, M;
  cin >> N >> M;
  vector<int> w(N);
  for (int i = 0; i < N; i++){
    cin >> w[i];
  }
  vector<int> l(M), v(M);
  for (int i = 0; i < M; i++){
    cin >> l[i] >> v[i];
  }
  vector<pair<int, int>> P(M + 1);
  for (int i = 0; i < M; i++){
    P[i] = make_pair(v[i], l[i]);
  }
  P[M] = make_pair(0, 0);
  sort(P.begin(), P.end());
  for (int i = 0; i < M; i++){
    P[i + 1].second = max(P[i + 1].second, P[i].second);
  }
  int wmax = *max_element(w.begin(), w.end());
  int vmin = *min_element(v.begin(), v.end());
  if (wmax > vmin){
    cout << -1 << endl;
  } else {
    long long ans = INF;
    vector<int> p(N);
    for (int i = 0; i < N; i++){
      p[i] = i;
    }
    while (1){
      vector<long long> w2(N);
      for (int i = 0; i < N; i++){
        w2[i] = w[p[i]];
      }
      vector<long long> S(N + 1);
      S[0] = 0;
      for (int i = 0; i < N; i++){
        S[i + 1] = S[i] + w2[i];
      }
      vector<long long> x(N);
      x[0] = 0;
      for (int i = 1; i < N; i++){
        long long minx = x[i - 1];
        for (int j = 0; j < i; j++){
          int wsum = S[i + 1] - S[j];
          auto itr = lower_bound(P.begin(), P.end(), make_pair(wsum, -INF)) - 1;
          long long d = (*itr).second;
          minx = max(minx, x[j] + d);
        }
        x[i] = minx;
      }
      ans = min(ans, x[N - 1]);
      if (!next_permutation(p.begin(), p.end())){
        break;
      }
    }
    cout << ans << endl;
  }
}