// Problem : 
// bit.ly/pentagon03 
#include<bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(),(v).end() 
#define sz(v) (int)((v).size())
#define ini(st,en,X) fill(&st,&en,decltype(st)(X))
#define rep(i,n) for(int i=0;i<(n);i++)
#define repr(i,a,b) for(int i=(a);i<=(b);i++)
#define nl '\n'
#define sp ' '
using ll = long long;
using pii = pair<int,int>;
void dbg(string s = "STILL WORKING"){puts(s.c_str());}

void solve(){
	int n,m;
	cin>>n>>m;
	vector<int> arr(n);
	vector<pii> v(m+1);
	rep(i,n) cin>>arr[i];
	repr(i,1,m) cin>>v[i].second>>v[i].first;
	rep(i,n){
		int flag=0;
		repr(j,1,m){
			if(arr[i]>v[j].first){
				flag=1;
				break;
			}
		}
		if(flag){
			cout<<-1<<nl;
			return;
		}
	}
	sort(all(v));
	int dp[m+1]={};
	repr(i,1,m)
		dp[i] = max(dp[i-1],v[i].second);
	sort(all(arr));
	int ans = 2e9;
	do{
		int psum[n],dis[n]={0,},sum=0;
		rep(i,n){
			sum+=arr[i];
			psum[i]=sum;
		}
		rep(i,n){
			repr(j,i+1,n-1){
				int rsum = psum[j];
				if(i) rsum-=psum[i-1];
				int idx = lower_bound(all(v),pii(rsum,0)) - v.begin() - 1;
				dis[j] = max(dis[j],dis[i]+dp[idx]);
			}
		}
		ans = min(ans,dis[n-1]);
	}while(next_permutation(all(arr)));
	cout<<ans<<nl;
}

int main(){
	ios::sync_with_stdio(false); cin.tie(0);
	int TC=1;

	repr(tc,1,TC){
		
		solve();
	}

	return 0;
}


// Solution
/*



*/

#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>

typedef long long ll;
typedef std::pair<ll, ll> pll;
const ll INF = (1LL << 60);

struct segtree {
  int i, j;
  ll val;
  segtree *l, *r;
  segtree(std::vector<pll> &ar, int _i, int _j) : i(_i), j(_j) {
    if (i == j) {
      val = ar[i].second;
      l = r = NULL;
    } else {
      int k = (i+j) >> 1;
      l = new segtree(ar, i, k);
      r = new segtree(ar, k+1, j);
      val = std::max(l->val, r->val);
    }
  }
  ll query(int _i, int _j) {
    if (_i <= i and j <= _j) {
      return val;
    } else if (_j < i or j < _i) {
      return 0;
    } else {
      return std::max(l->query(_i, _j), r->query(_i, _j));
    }
  }
};

struct graph {
  int n;
  ll **mat;
  ll *dp;
  graph (int n) : n(n) {
    mat = new ll*[n];
    for (int u = 0; u < n; ++u)
      mat[u] = new ll[n];
    dp = new ll[n];
  }
  void change_edge(int u, int v, ll w) {
    mat[u][v] = w;
  }
  ll dfs(int u) {
    if (u == n-1) return 0;
    if (dp[u] != -1)  return dp[u];
    dp[u] = 0;
    for (int v = u+1; v < n; ++v)
      dp[u] = std::max(dp[u], dfs(v) + mat[u][v]);
    return dp[u];
  }
};

int N, M;
std::vector<ll> W;
std::vector<pll> P;

int main() {
  std::cin >> N >> M;
  ll maxw = 0;
  for (int i = 0; i < N; ++i) {
    ll w; std::cin >> w;
    W.push_back(w);
    maxw = std::max(maxw, w);
  }
  std::sort(W.begin(), W.end());

  bool unavoid_collapse = false;

  for (int i = 0; i < M; ++i) {
    ll l, v;  std::cin >> l >> v;
    P.push_back({v, l});
    if (maxw > v)
      unavoid_collapse = true;
  }
  std::sort(P.begin(), P.end());
  segtree *root = new segtree(P, 0, M-1);

  if (unavoid_collapse) {
    std::cout << "-1\n";
    return 0;
  }

  graph g(N);
  ll ans = (1LL << 60);
  do {
    /*for (int w : W)
      std::cout << w << " ";
    std::cout << "\n";*/
    for (int i = 0; i < N; ++i) {
      ll s = W[i];
      for (int j = i+1; j < N; ++j) {
        s += W[j];
        int k = -1;
        for (int jump = M; jump >= 1; jump >>= 1)
          while (k + jump < M and P[k + jump].first < s)
            k += jump;
        //std::cout << i << " " << j << " " << k << "\n";
        g.change_edge(i, j, root->query(0, k));
      }
    }
    for (int u = 0; u < N; ++u) g.dp[u] = -1;
    ll dist = g.dfs(0);
    ans = std::min(ans, dist);
    //std::cout << dist << "\n";
    //std::cout << "-----\n";
  } while (std::next_permutation(W.begin(), W.end()));
  std::cout << ans << "\n";

  return 0;
}
