/*  -*- coding: utf-8 -*-
 *
 * c.cc: C - Camels and Bridge
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 8;
const int MAX_M = 100000;
const long long LINF = 1LL << 62;

/* typedef */

typedef long long ll;
typedef pair<int,int> pii;

/* global variables */

int wis[MAX_N], ps[MAX_N], cls[MAX_N];
int vs[MAX_M], mls[MAX_M + 1];
pii vls[MAX_M];

/* subroutines */

/* main */

int main() {
  int n, m;
  scanf("%d%d", &n, &m);

  for (int i = 0; i < n; i++) scanf("%d", wis + i);
  sort(wis, wis + n);

  for (int i = 0; i < m; i++)
    scanf("%d%d", &vls[i].second, &vls[i].first);
  sort(vls, vls + m);

  if (wis[0] > vls[0].first) { puts("-1"); return 0; }

  for (int i = 0; i < m; i++) vs[i] = vls[i].first;

  mls[0] = 0;
  for (int i = 0; i < m; i++) mls[i + 1] = max(mls[i], vls[i].second);

  for (int i = 0; i < n; i++) ps[i] = i;

  ll minl = LINF;
  do {
    cls[0] = 0;
    for (int i = 1; i < n; i++) {
      int wsum = wis[ps[i]];
      ll lsum = 0;
      cls[i] = 0;
      for (int j = i - 1; j >= 0; j--) {
	wsum += wis[ps[j]];
	int k = lower_bound(vs, vs + m, wsum) - vs;
	if (mls[k] > lsum + cls[i]) cls[i] = mls[k] - lsum;
	lsum += cls[j];
      }
    }

    ll sum = 0;
    for (int i = 1; i < n; i++) sum += cls[i];
    if (minl > sum) minl = sum;
  } while (next_permutation(ps, ps + n));

  printf("%lld\n", minl);
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define int long long
 
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t=1;
	//cin >>t;
	while(t--){
		int n,q,x=0,y;
		cin>>n>>q;
		int a[n],b[n];
		for(int i=0;i<n;i++){
			cin >>a[i];
			b[i]=a[i]-x-1;
			x=a[i];
		}
		for(int i=1;i<n;i++)
			b[i]=b[i]+b[i-1];
		while(q--){
			int l=0,r=2e18,m;
			cin>>x;
			while(l<=r){
				m=(l+r)/2;
				if(m-(lower_bound(a,a+n,m)-a)>=x+1)
				r=m-1;
				else
				l=m+1;
			}
			cout<<r<<endl;
		}
	}
	return 0;
}