#include <bits/stdc++.h>

#define int long long
#define double long double
#define ff first
#define ss second
#define endl '\n'
#define ii pair<int, int>
#define mp make_pair
#define mt make_tuple
#define DESYNC                      \
  ios_base::sync_with_stdio(false); \
  cin.tie(0);                       \
  cout.tie(0)
#define pb push_back
#define vi vector<int>
#define vii vector<ii>
#define all(x) x.begin(), x.end()
#define EPS 1e-9
#define INF 1e18
#define ROOT 1
#define curtime chrono::steady_clock::now().time_since_epoch().count
#define rep(i, beg, n, s) for (int i = beg; i < n; i += s)
using ll = long long;
using namespace std;
const double PI = acos(-1);
const int M = 1000000007;
// const int M = 998244353;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline int mod(int n, int m = M) {
  int ret = n % m;
  if (ret < 0) ret += m;
  return ret;
}

int exp(int n, int k, int m = M) {
  if (k == 0) return 1;
  if (k == 1) return n;
  int ax = exp(n, k / 2, m);
  ax = mod(ax * ax, m);
  if (k % 2) ax = mod(ax * n, m);
  return ax;
}

int gcd(int a, int b) {
  if (a == 0)
    return b;
  else
    return gcd(b % a, a);
}

int solve(const vector<int> &v, const vector<ii> &b, const vector<int> &calc) {
  int n = v.size();
  int g[n][n];
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      int id = upper_bound(all(b), ii(v[i] + v[j] - 1, INF)) - b.begin();
      id--;
      if (id == -1)
        g[i][j] = 0;
      else
        g[i][j] = calc[id];
    }
  }

  vector<int> d(n, 0);
  d[0] = 0;
  for (int i = 1; i < n; i++) {
    int sum = v[i];
    for (int j = i - 1; j >= 0; j--) {
      sum += v[j];
      int id = upper_bound(all(b), ii(sum - 1, INF)) - b.begin();
      id--;
      int l = 0;
      if (id != -1) l = calc[id];
      d[i] = max(d[i], d[j] + l);
    }
  }
  return d[n - 1];
}

//#define MULTIPLE_TEST_CASE
void solution() {
  int n, m;
  cin >> n >> m;
  vector<ii> b(m);
  vector<int> calc;
  vi v(n);
  int mx = -INF, mn = INF;
  for (int &x : v) cin >> x, mx = max(mx, x);
  for (ii &x : b) cin >> x.ss >> x.ff, mn = min(mn, x.ff);
  int ans = INF;

  if (mx > mn) {
    cout << -1 << endl;
    return;
  }

  sort(all(v));
  sort(all(b));

  for (ii x : b) {
    if (calc.size() == 0)
      calc.pb(x.ss);
    else
      calc.pb(max(calc.back(), x.ss));
  }

  do {
    ans = min(ans, solve(v, b, calc));
  } while (next_permutation(all(v)));

  cout << ans << endl;
}

int32_t main() {
  DESYNC;
  int t = 1;
#ifdef MULTIPLE_TEST_CASE
  cin >> t;
#endif
  while (t--) solution();
}

#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;

template<class T>
struct graph{
    struct edge{
        int to;
        T cost;
        edge(int to, T cost) : to(to), cost(cost){}
        bool operator<(const edge& r)const { return cost < r.cost; }
    };
    int V;
    vector< vector< edge > > adj;
    vector< T > dist;
    vector< int > prev;
    graph(){}
    graph(int n = 0){
        init(n);
    }

    void init(int size){
        V = size;
        adj.assign(size, vector<edge>());
    }

    void add_edge(int from, int to, T cost){
        adj[from].push_back(edge(to, cost));
    }

    void Dijkstra(int from, T inf){
        using P = pair<T, int>;
        priority_queue< P, vector<P>, greater<P> > q;
        dist.assign(V, inf);
        prev.assign(V, -2);
        dist[from] = 0;
        prev[from] = -1;
        q.push(P(0, from));
        while(!q.empty()){
            P p = q.top();
            q.pop();
            int v = p.second;
            if(dist[v] < p.first) continue;
            for(edge e: adj[v]){
                if(dist[v] + e.cost < dist[e.to]){
                    dist[e.to] = dist[v] + e.cost;
                    prev[e.to] = v;
                    q.push(P(dist[e.to], e.to));
                }
            }
        }
    }

    void get_path(int to, vector<int>& path){
        path.clear();
        if(prev[to] == -2) return;
        while(prev[to] != -1){
            path.push_back(to);
            to = prev[to];
        }
        path.push_back(to);
        reverse(path.begin(), path.end());
    }
};

int main(void){
    using P = pair<int, int>;
    int n, m;
    cin >> n >> m;
    vector< int > w(n);
    vector< P > vl;
    for(int i=0;i<n;i++) cin >> w[i];
    for(int i=0;i<m;i++){
        int l, v;
        cin >> l >> v;
        vl.push_back(P(v, l));
    }

    {
        int wmx = 0;
        for(int i=0;i<n;i++) wmx = max(wmx, w[i]);
        for(int i=0;i<m;i++){
            if(vl[i].first < wmx){
                puts("-1");
                return 0;
            }
        }
    }
    vl.push_back(P(1e9, 0));
    sort(vl.begin(), vl.end());
    vector< int > lb(m+1, 0);
    lb[0] = 0;
    for(int i=1;i<=m;i++){
        lb[i] = max(lb[i-1], vl[i-1].second);
    }
    auto f = [&](int v){
        int ng = -1, ok = m;
        while(ng + 1 < ok){
            int mid = (ng + ok) / 2;
            if(v <= vl[mid].first) ok = mid;
            else ng = mid;
        }
        return lb[ok];
    };
    int ans = 1e9;
    sort(w.begin(), w.end());

    do{
        graph<int> g(n);
        for(int i=0;i<n;i++){
            int c = w[i];
            for(int j=i+1;j<n;j++){
                c += w[j];
                g.add_edge(i, j, -f(c));
            }
        }
        g.Dijkstra(0, 1e9);
        ans = min(ans, -g.dist[n-1]);
    }while(next_permutation(w.begin(), w.end()));
    cout << ans << endl;
}
