#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>
#include <cassert>


using namespace std;
//using namespace atcoder;

#define REP(i, n) for (int i=0; i<(n); ++i)
#define RREP(i, n) for (int i=(int)(n)-1; i>=0; --i)
#define FOR(i, a, n) for (int i=(a); i<(n); ++i)
#define RFOR(i, a, n) for (int i=(int)(n)-1; i>=(a); --i)

#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl;

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}

template<class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    return os << "(" << p.first << " " << p.second << ")";
}

template<class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;

const ll MOD = 1e9 + 7;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
const ld eps = 1e-9;


// edit
const int lim = 100000007;
ll v2l[lim]; // 重さがv以上の橋の内、最も短いもの

ll get_l(ll v) {
    if (v < lim) return v2l[v];
    else return v2l[lim - 1];
}

ll func(const vector<ll> &v) {
    vector<ll> dist(v.size(), 0);
    dist[0] = 0;

    for (int i = 0; i < v.size(); ++i) {
        ll sum = 0;
        for (int j = i; j < v.size(); ++j) {
            sum += v[j];
            ll l = get_l(sum - 1);
            chmax(dist[j], dist[i] + l);
        }
    }

    return dist.back();
}


void solve() {
    int n, m;
    cin >> n >> m;
    vector<ll> w(n);
    REP(i, n) cin >> w[i];
    vector<pair<ll, ll>> lv(m);
    REP(i, m) {
        cin >> lv[i].first >> lv[i].second;
        chmax(v2l[lv[i].second], lv[i].first);
    }

    for (int i = 0; i + 1 < lim; ++i) {
        chmax(v2l[i + 1], v2l[i]);
    }
    {
        ll max_w = *max_element(ALL(w));
        ll min_v = LINF;
        REP(i, m) {
            chmin(min_v, lv[i].second);
        }
        cerr << max_w << " " << min_v << endl;
        if (max_w > min_v) {
            cout << -1 << endl;
            return;
        }
    }

    ll ans = LINF;
    sort(ALL(w));
    do {
        ll val = func(w);
        chmin(ans, val);
    } while (next_permutation(ALL(w)));
    cout << ans << endl;


}


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
//    std::ifstream in("input.txt");
//    std::cin.rdbuf(in.rdbuf());

    solve();


    return 0;
}

#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
// please, read the question correctly (do you need set or multiset)???
const int N=100010; //check the limits, dummy
int a[11];
int n, m;
int mp[100000010], mp1[100000010], l[N], v[N];
int main(){
	int t;
	scanf("%d%d",&n,&m);
	int mx1= 0;
	for(int i=0; i<n; ++i){
		scanf("%d",a+i);
		mx1=max(mx1, a[i]);
	}
	int mx = 0;
	bool bl =1;
	for(int i=0; i<m; ++i){
		scanf("%d%d",&l[i], &v[i]);
		mp[v[i]]=max(mp[v[i]], l[i]);
		mx=max(mx, v[i]);
		if(mx1>v[i]){
			bl=0;
		}
	}
	if(!bl){
		cout<<"-1"<<endl;
		return 0;
	}
	int tmp = 0;
	mp1[0]=0;
	++mx;
	for(int i=1; i<=mx; ++i){
		mp1[i]=max(mp1[i-1], mp[i-1]);
	}
	sort(a, a+n);
	int ans = 1e9;
	int cnt = 0;
	do{
		++cnt;
		int dis[10]={0};
		for(int i=0; i<n; ++i){
			tmp=a[i];
			dis[i]=0;
			for(int j=i-1; j>=0; --j){
				tmp+=a[j];
				tmp = min(tmp, mx);
				dis[i]=max(dis[i], mp1[tmp]+dis[j]);
			}
		}
		ans=min(ans, dis[n-1]);
	}while(next_permutation(a, a+n));
	cout<<ans<<endl;
}