#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std;
void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int N, M, w[10];
int l[101010], v[101010];
ll dp[10][10];
//---------------------------------------------------------------------------------------------------
ll solve() {
	rep(i, 0, N) rep(j, 0, M) if (v[j] < w[i]) return -1;

	map<int, int> pr;
	rep(i, 0, M) {
		if (pr.count(l[i]) == 0) pr[l[i]] = inf;
		chmin(pr[l[i]], v[i]);
	}

	set<pair<ll, int>> lens; // {weight, len}

	int pre = inf;
	for (auto ite = pr.rbegin(); ite != pr.rend(); ite++) if (ite->second < pre) {
		lens.insert({ ite->second, ite->first });
		pre = ite->second;
	}

	vector<int> ord;
	rep(i, 0, N) ord.push_back(i);
	ll ans = infl;
	do {
		rep(i, 0, N) rep(j, 0, N) dp[i][j] = infl;
		rep(i, 0, N) dp[i][i] = 0;

		rep(len, 2, N + 1) rep(l, 0, N) {
			int r = l + len - 1;
			if (N <= r) continue;

			ll weight = 0;
			rep(i, l, r + 1) weight += w[ord[i]];

			auto ite = lens.lower_bound({ weight, -1 });
			if (ite == lens.begin()) {
				dp[l][r] = 0;
			}
			else {
				ite--;
				dp[l][r] = ite->second;
			}

			rep(c, l, r + 1) chmax(dp[l][r], dp[l][c] + dp[c][r]);
		}
		chmin(ans, dp[0][N - 1]);
	} while (next_permutation(all(ord)));

	return ans;
}
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> M;
	rep(i, 0, N) cin >> w[i];
	rep(i, 0, M) cin >> l[i] >> v[i];
	cout << solve() << endl;
}






#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

#define mp make_pair
#define fr first
#define sc second

int main(){
	ld x,y,rr;
	cin>>x>>y>>rr;
	
	x+=200100.;
	y+=200100.;
	
	ll X=10000*x+0.5;
	ll Y=10000*y+0.5;
	ll R=10000*rr+0.5;
	
	ll ret=0;
	for(ll s=x-rr-10;s<x+rr+10;s++){
		ll b,u;
		ll l=y-rr-10,r=y+1;
		//cerr<<l<<" "<<r<<endl;
		while(l<r){
			ll t=(l+r)/2;
			ll d=(s*10000-X)*(s*10000-X)+(t*10000-Y)*(t*10000-Y);
			//cerr<<t<<" "<<d<<" "<<R<<endl;
			if(d<=R*R)r=t;
			else l=t+1;
		}
		b=l;
		l=y; r=y+rr+10;
		//cerr<<l<<" "<<r<<endl;
		while(l<r){
			ll t=(l+r+1)/2;
			ll d=(s*10000-X)*(s*10000-X)+(t*10000-Y)*(t*10000-Y);
			if(d<=R*R)l=t;
			else r=t-1;
		}
		u=l;
		if(b<=u)ret+=u-b+1;
		//cout<<s<<" "<<b<<" "<<u<<endl;
	}
	cout<<ret<<endl;
}
