#include <bits/stdc++.h>
#define fi first
#define se second
//#define ivorysi
#define enter putchar('\n')
#define space putchar(' ')

#define pii pair<int,int>
typedef long long int64;
using namespace std;

template<class T>
void read(T &res) {
	res = 0;T f = 1;char c = getchar();
	while(c < '0' || c > '9') {
		if(c == '-') f = -1;
		c = getchar();
	}
	while(c >= '0' && c <= '9') {
		res = res * 10 + c - '0';
		c = getchar();
	}
	res *= f;
}
template<class T>
void out(T x) {
	if(x < 0) {x = -x;putchar('-');}
	if(x >= 10) out(x / 10);
	putchar('0' + x % 10);
}
const int MAXM = 100005;
int N,M;
int64 w[10],l[MAXM],v[MAXM],ans,sum[10],dis[10][10],dp[10];
int64 val[MAXM],len[MAXM];
int a[10],id[MAXM];
bool vis[10];
void dfs(int d) {
	if(d > N) {
		for(int i = 1 ; i <= N ; ++i) {
			sum[i] = sum[i - 1] + w[a[i]];
		}
		memset(dis,0,sizeof(dis));
		for(int j = 1 ; j <= N ; ++j) {
			for(int t = j + 1 ; t <= N ; ++t) {
				int cv = sum[t] - sum[j - 1];
				int p = lower_bound(val + 1,val + M + 1,cv) - val - 1;
				if(val[p] < cv) {
					dis[j][t] = len[p];
				}
			}
		}
		memset(dp,0,sizeof(dp));
		for(int i = 1 ; i <= N ; ++i) {
			for(int j = i + 1 ; j <= N ; ++j) {
				dp[j] = max(dp[j],dp[i] + dis[i][j]);
			}
		}
		ans = min(ans, dp[N]);
		return;
	}
	for(int i = 1 ; i <= N ; ++i) {
		if(!vis[i]) {
			a[d] = i;
			vis[i] = 1;
			dfs(d + 1);
			vis[i] = 0;
		}
	}
}
int main() {
#ifdef ivorysi
	freopen("f1.in","r",stdin);
#endif
	read(N);read(M);
	for(int i = 1 ; i <= N ; ++i) read(w[i]);
	for(int i = 1 ; i <= M ; ++i) {
		read(l[i]);read(v[i]);
		id[i] = i;
		ans += l[i];
	}
	ans = ans * N;
	sort(id + 1,id + M + 1,[](int a,int b) {return v[a] < v[b] || (v[a] == v[b] && l[a] > l[b]);});
	for(int i = 1 ; i <= M ; ++i) {
		val[i] = v[id[i]];
		len[i] = l[id[i]];
		len[i] = max(len[i],len[i - 1]);
	}
	for(int i = 1 ; i <= M ; ++i) {
		for(int j = 1 ; j <= N ; ++j) {
			if(w[j] > v[i]) {
				puts("-1");
				return 0;
			}
		}
	}
	dfs(1);
	out(ans);enter;
	return 0;
}

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>
//#include <atcoder/all>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define sz(v) (int)(v).size()
#define vi vector<int>
#define vll vector<long long>

using namespace std;
//using namespace atcoder;
//using mint = modint1000000007;
//using mint = modint998244353;
//using mint = modint;

typedef long long ll;
typedef long double ld;

using P = pair<ll, ll>;
template<typename T>
struct Edge {
    int u, v;
    T cost;
    Edge(int u, int v, T c) : u(u), v(v), cost(c) {}
    bool operator< (const Edge &e) const {return cost < e.cost;}
};

static const long long MOD = 1000000007;
static const long long LINF = (ll)(1e18+99);
static const int INF = 1e9+99;

ll ans = LINF;

int main(void) {
    int N, M;
    cin >> N >> M;
    vll W(N, 0), perm(N, 0);
    vector<P> V;

    rep(i, 0, N) cin >> W[i];
    rep(i, 0, N) perm[i] = i;
    rep(i, 0, M) {
        ll l, v;
        cin >> l >> v;
        V.pb(mp(v, l));
    }

    sort(all(V));
    rep (i, 0, N) if (W[i] > V[0].first) {
      puts("-1");
      return 0;
    }
    rep(i, 1, M) V[i].second = max(V[i].second, V[i-1].second);
   

    // ラクダの順列全探索
    do {
        vll dist(N, 0); // ラクダの配置座標
       
        rep(i, 1, N) {
            ll w = W[perm[i]];
            dist[i] = dist[i-1];
            per(j, 0, i) {
                w += W[perm[j]];
                int x = lower_bound(all(V), mp(w, 0LL)) - V.bg;
                if (x==0) continue;
                ll mxl = V[x-1].second;
                dist[i] = max(dist[i], dist[j]+mxl); 
            }
        }
        ans = min(dist[N-1], ans);

    } while (next_permutation(all(perm)));
    
    cout << ans << endl;
    return 0;
}




