#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define forn(i,n) for(int i = 0; i < (int) n; i++)
#define ios ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)

using namespace std;
typedef long long ll;

int n;
vector<int> w, maxL;
vector<pair<int,int>> seg;

ll mindist(vector<int>& o) {
  ll ans = 0;
  vector<ll> pos(n);

  for(int i = 1; i < n; i++) {
    int sumw = w[o[i]];
    pos[i] = pos[i-1];

    for(int st = i-1; st >= 0; st--){
      sumw += w[o[st]];
      // sumw = weight of cows [st, i]

      auto lo = lower_bound(all(seg), pair<int,int>{sumw, -1});
      if (lo == seg.begin()) continue;
      int idx = (lo - seg.begin()) - 1;

      pos[i] = max(pos[i], pos[st] + maxL[idx]);
    }
  }

  return pos.back();
}

int main() {
  ios;
  int m;
  cin >> n >> m;

  w.resize(n);
  int mxw = 0;
  forn(i,n){
    cin >> w[i];
    mxw = max(mxw, w[i]);
  }

  //seg[i] = {v,l}
  seg.resize(m);
  forn(i,m) cin >> seg[i].second >> seg[i].first;
  sort(all(seg));

  maxL.resize(m);
  forn(i,m){
    maxL[i] = seg[i].second;
    if (i) maxL[i] = max(maxL[i], maxL[i-1]);
  }

  if (seg[0].first < mxw) {
    cout << "-1";
    return 0;
  }

  vector<int> o(n);
  iota(all(o), 0);

  long long ans = 1ll << 60;
  do{
    ans = min(ans, mindist(o));
  }while(next_permutation(all(o)));

  cout << ans << "\n";
}

#include <bits/stdc++.h>
using namespace std;
int main(){
  #define int long long
  int N,M,maxW=0,ans=0;
  cin>>N>>M;
  vector<int> w(N),l(M),v(M),p(N);
  vector<pair<int,int>> rock(M);
  for(int i=0;i<N;i++){
    cin>>w.at(i);
    maxW=max(maxW,w.at(i));
    p.at(i)=i;
  }
  for(int i=0;i<M;i++){
    cin>>l.at(i)>>v.at(i);
    ans+=l.at(i);
    if(maxW>v.at(i)){
      cout<<-1<<endl;
      return 0;
    }
    rock.at(i)={v.at(i),l.at(i)};
  }
  ans*=N;
  sort(rock.begin(),rock.end());
  unordered_map<int,int> minW;
  for(int i=0;i<M;i++){
    if(i==0){minW[rock.at(i).first+1]=rock.at(i).second;}
    if(i>0){minW[rock.at(i).first+1]=max(rock.at(i).second,minW[rock.at(i-1).first+1]);}
  }
  sort(w.begin(),w.end());
  sort(v.begin(),v.end());
  do{
    vector<int> d(N-1,0);
    for(int i=0;i<N;i++){//右端
      for(int j=0;j<=i;j++){//左端
        int sumW=0,sumD=0;
        for(int k=j;k<=i;k++){//sumD,sumWの計算
          sumW+=w.at(k);
          if(k<i){sumD+=d.at(k);}
        }
        int left=0,right=M-1,sumWW=-1;
        while(left<=right){
          int mid=left+(right-left)/2;
          if(v.at(mid)+1<=sumW){
            left=mid+1;
            sumWW=max(sumWW,v.at(mid)+1);
          }
          else{right=mid-1;}
        }
        int stkj=minW[sumWW];//必要距離
        if(stkj>sumD){d.at(i-1)+=stkj-sumD;}
      }
    }
    int Qans=0;
    for(int i=0;i<N-1;i++){Qans+=d.at(i);}
    ans=min(ans,Qans);
  }while(next_permutation(w.begin(),w.end()));
  cout<<ans<<endl;
}