#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define fi first
#define se second
#define mset(a,b) memset(a, b, sizeof(a))
#define dbg(x) cout << "[" << #x << "]: " << x << endl;
#define forn(i,n) for(int i=0; i < n;i++)
#define forab(i,a,b) for(int i = a; i <= b; i++)
#define forba(i,b,a) for(int i = b; i >= a; i--)
#define each(val, v) for(auto val : v)
#define abs(u) (u >= 0 ? u : -u)

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;

const int MAXN = 2e5 + 5;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9+7;

void solve(){

    int n,m;
    cin >> n >> m;
    vi w(n);
    int mais_gordo = 0;
    forn(i,n){
        cin >> w[i];
        mais_gordo = max(mais_gordo, w[i]);
    }

    vector<pii> a(m);
    int minn_guenta = INF;
    forn(i,m){
        cin >> a[i].fi;
        cin >> a[i].se;
        minn_guenta = min(minn_guenta, a[i].se);
    }

    if(mais_gordo > minn_guenta){
        cout << -1 << '\n';
        return;
    }

    sort(a.begin(), a.end());

    stack<pii> s;

    forn(i,m){
        while(!s.empty() && s.top().se > a[i].se){
            s.pop();
        }
        s.push(a[i]);
    }

    vector<pii> valids;

    while(!s.empty()){
        pii aux = s.top();
        valids.pb(aux);
        s.pop();
    }

    m = valids.size();
    reverse(valids.begin(), valids.end());

    if(n == 1){
        cout << 0 << '\n';
        return;
    }


    sort(w.begin(), w.end());

    int maior = w[n-1];
    w.pop_back();

    int ans = INF;
    do{

        vi a(n);

        forn(i,n-1){
            a[i] = w[i];
        }

        a[n-1] = maior;



        vi min_v(n,0);

        

        forn(i, n-1){
            int my = min_v[i];

            int at = 0;
            int vat = 0;
            int soma = w[i];

            for(int j = i+1; j < n; j++){
                soma += w[j];
                while( at < m && valids[at].se < soma){
                    
                    vat = valids[at].fi;
                    at++;

                }

                min_v[j] = max(min_v[j], vat+min_v[i]);
            }
        }

        ans = min(ans, min_v[n-1]);

        

    }while(  next_permutation(w.begin(), w.end()));

    cout << ans << '\n';
}

int main(){

    ios::sync_with_stdio(false); cin.tie(NULL);

    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }

    return 0;
}
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;

typedef long long int ll;
#define endl '\n'
#define ld long double
#define all(a) a.begin(),a.end()
#define int long long
#define pb push_back
#define pii pair <int, int>
#define ff first
#define ss second
#define sz(v) (int)v.size() 
#define UB upper_bound
#define LB lower_bound
#define BP(x) __builtin_popcountll(x)
#define PQS priority_queue <int, vector<int>, greater<int> > 
#define OST tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update>
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int getRand(int l, int r) {
  uniform_int_distribution<int> uid(l, r);
  return uid(rng);
}

const int INF = 1e18 + 0;
const int mod = 1e9 + 7;
//const int mod = 998244353;
const int N = 1e5+ 5;

int dp[10][10], pre[10], cap[N], L[N];
vector <pii> vv;

bool com(pii p1, pii p2) {
  if(p1.ff == p2.ff) return p1.ss > p2.ss;
  return p1.ff > p2.ff;
}

int get(int x, int m) {
  int lo = 0, hi = m-1;
  int ret = 0;

  while(hi >= lo) {
    int mid = (hi + lo)/2;
    if(x > vv[mid].ff) {
      ret = max(ret, vv[mid].ss);
      hi = mid-1;
    }
    else lo = mid+1;
  }
  return ret;
}

void solve() {
  int n, m, f = 0;
  cin >> n >> m;
  
  vector <int> v(n+1,0);

  for(int i = 1; i <= n; i++) cin >> v[i];
  sort(v.begin()+1, v.end());

  for(int i = 1; i <= m; i++) {
    cin >> L[i] >> cap[i];
    if(v.back() > cap[i]) f = 1;
    vv.pb({cap[i], L[i]});
  }

  if(f) {
    cout << "-1\n"; return;
  }

  sort(all(vv), com);
  
  int mx = -1;
  for(int i = m-1; i >= 0; i--) {
    mx = max(vv[i].ss, mx);
    vv[i].ss = mx;
  }
  
  int ans = INF;
  do {
    memset(dp,0,sizeof(dp));
    memset(pre,0,sizeof(pre));
    
    for(int i = 1; i <= n; i++) {
      pre[i] = v[i] + pre[i-1];
    }

    for(int i = 1; i <= n; i++) {
      for(int j = i+1; j <= n; j++) {
         int x = pre[j] - pre[i-1];
         int res = get(x, m);
         dp[i][j] =res;
      }
    }
    for(int i = 1; i <= n; i++) {
      for(int j = 1; j <= n; j++) {
         for(int k = i; k <= j; k++) {
           dp[i][j] = max(dp[i][j], dp[i][k] + dp[k][j]);
         }
      }
    }
    ans = min(ans, dp[1][n]);

  } while(next_permutation(v.begin()+1, v.end()));
  
  cout << ans << '\n';
}

/*
  * overflow, array bounds
  * do smth instead of nothing and stay organized
*/
signed main() {   
  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

  #ifndef ONLINE_JUDGE
   freopen("input.txt", "r", stdin);
   freopen("output.txt", "w", stdout);
  #endif
   int t = 1; //cin >> t;
   for(int i = 1; i <= t; i++) {
   //  cout << "Case #" << i << ": ";
     solve();
  }
}    

/*

*/