#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef map<int,int> mii;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<long long> vl;
typedef vector<vector<ll>> vll;
typedef vector<bool> vb;
typedef set<int> si; 
typedef queue<int> qi;
typedef stack<int> sti;
typedef priority_queue<int> pqi;
#define fori(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i,b,a) for(int i = (b); i >= (a); --i)
#define all(a) (a).begin(), (a).end()
//#define __builtin_popcountll bitCountLL
//#define __builtin_popcount bitCount
//__builtin_ctz 末尾0的个数, __builtin_clz 前导0的个数
//__builtin_ffs 最后一个1的位置
mt19937 mt_rand(chrono::high_resolution_clock::now().time_since_epoch().count());
//std::uniform_int_distribution<long long> rg(1,1e18);
#define maxn 100005
#define Mod 1000000007
const int INF = 2e9;
const ll ML = 4e18;
vii perm;
int n, m;
void dfs(int i, vector<int>& rs, int state) {
    if(i == n) {
        perm.push_back(rs);
        return;
    }
    for(int j = 0; j < n; j++) {
        if(state & (1 << j) ){
            rs.push_back(j + 1);
            dfs(i + 1, rs, state ^ (1 << j) );
            rs.pop_back();
        }
    }
}
int ans;
void helper(vi& w, vi& p, vi& b, vi& ma) {
    vi a(n);
    fori(i,0,n) a[i] = w[p[i] - 1];
    vi sum(n);
    sum[0] = a[0];
    fori(i,1,n) sum[i] = a[i] + sum[i - 1];
    int rs = 0;
    vii dp(n, vi(n, 0));
    fori(i,0,n) {
        rep(j, i - 1, 0) {
            int dw = (j == 0 ? sum[i] : sum[i] - sum[j - 1]);
            int idx = lower_bound(all(b), dw) - b.begin();
            dp[j][i] = (idx == 0 ? 0 : ma[idx -1]);
            rep(k,i-1, j) {
                dp[j][i] = max(dp[j][i], dp[k][i] + dp[j][k]);
            }
        }
    } 
    ans = min(ans, dp[0][ n -1]);
}

void solve() {
    cin >> n >> m;
    vi w(n);
    vector<pii> bridge(m);
    fori(i,0,n) {
        cin >> w[i];
    }
    fori(i,0,m) cin >> bridge[i].second >> bridge[i].first;
    sort(all(bridge));
    fori(i,0,n) {
        if(w[i] > bridge[0].first) {
            cout << -1 << endl;
            return;
        }
    }
    vi mx(m);
    mx[0] = bridge[0].second;
    fori(i,1,m) mx[i] = max(mx[i-1], bridge[i].second);
    vi rs;
    dfs(0,rs,(1 << n) - 1);
    ans =  INF;
    vi b(m);
    fori(i,0,m) b[i] = bridge[i].first;
    fori(i, 0 , perm.size()) helper(w, perm[i], b, mx);
    cout << ans << endl;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
	//cout.precision(30); cout << fixed;
//	freopen("D:\\data_in.txt", "r", stdin);
   
    solve();
   
    /*
    clock_t start,finish;
    start = clock();
    
    finish = clock();
    cout << "\n" << (double)(finish - start) / (double)(CLOCKS_PER_SEC) * 1000 << "ms" << endl;
    */
    return 0;
}

/***************************************************************
 question:
 idea:
 tag:
 record:
 ***************************************************************/

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

template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

ll solve() {
  int n, m;
  cin >> n >> m;
  vector<ll> w(n);
  ll maxW = 0;
  rep(i, n) {
    cin >> w[i];
    chmax(maxW, w[i]);
  }
  vector<ll> l(m), v(m);
  rep(i, m) {
    cin >> l[i] >> v[i];
    if (v[i] < maxW) return -1;
  }

  // 前処理
  vector<ll> dist(1 << n, 0);
  for (int bit = 0; bit < (1 << n); ++bit) {
    ll W = 0;
    rep(i, n) {
      if (bit & (1 << i)) W += w[i];
    }
    rep(i, m) {
      if (v[i] < W) {
        chmax(dist[bit], l[i]);
      }
    }
  }

  // DP
  ll res = 1LL << 60;
  vector<int> ids(n);
  iota(ids.begin(), ids.end(), 0);
  do {
    vector<ll> dp(n, 0);
    for (int i = 1; i < n; ++i) {
      int bit = (1 << ids[i]);
      for (int j = i - 1; j >= 0; --j) {
        bit |= (1 << ids[j]);
        chmax(dp[i], dp[j] + dist[bit]);
      }
    }
    chmin(res, dp[n - 1]);
  } while (next_permutation(ids.begin(), ids.end()));

  return res;
}

int main() { cout << solve() << endl; }