#include<bits/stdc++.h>
#define int long long
using namespace std;
using ld=long double;
signed main(){
  int N; cin>>N;
  if(N==1)return puts("Yes"),0;
  vector<int> A(N),B(N),C(N),D(N);
  for(int i=0;i<N;i++)cin>>A[i]>>B[i];
  for(int i=0;i<N;i++)cin>>C[i]>>D[i];
  for(int i=0;i<N;i++){
    vector<pair<ld,ld>> v1,v2;
    for(int j=0;j<N;j++){
      if(j!=0)v1.push_back({atan2(A[0]-A[j],B[0]-B[j]),sqrt((A[0]-A[j])*(A[0]-A[j])+(B[0]-B[j])*(B[0]-B[j]))});
      if(j!=i)v2.push_back({atan2(C[i]-C[j],D[i]-D[j]),sqrt((C[i]-C[j])*(C[i]-C[j])+(D[i]-D[j])*(D[i]-D[j]))});
    }
    for(int j=0;j<N-1;j++){
      vector<pair<ld,ld>> v3,v4;
      for(int k=0;k<N-1;k++){
        ld a=v1[k].first-v1[0].first;
        if(a<0)a+=3.1415926535*2;
        v3.push_back({a,v1[k].second});
        a=v2[k].first-v2[j].first;
        if(a<0)a+=3.1415926535*2;
        v4.push_back({a,v2[k].second});
      }
      sort(v3.begin(),v3.end());sort(v4.begin(),v4.end());
      for(int k=0;k<N-1;k++){
        if(abs(v3[k].first-v4[k].first)>1e-3 || abs(v3[k].second-v4[k].second)>1e-3){
          goto home;
        }
      }
      return puts("Yes"),0;
      home:;
    }
  }
  puts("No");
}
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>

typedef long long ll;
typedef std::pair<ll, ll> pll;
const ll INF = (1LL << 60);

struct segtree {
  int i, j;
  ll val;
  segtree *l, *r;
  segtree(std::vector<pll> &ar, int _i, int _j) : i(_i), j(_j) {
    if (i == j) {
      val = ar[i].second;
      l = r = NULL;
    } else {
      int k = (i+j) >> 1;
      l = new segtree(ar, i, k);
      r = new segtree(ar, k+1, j);
      val = std::max(l->val, r->val);
    }
  }
  ll query(int _i, int _j) {
    if (_i <= i and j <= _j) {
      return val;
    } else if (_j < i or j < _i) {
      return 0;
    } else {
      return std::max(l->query(_i, _j), r->query(_i, _j));
    }
  }
};

struct graph {
  int n;
  ll **mat;
  ll *dp;
  graph (int n) : n(n) {
    mat = new ll*[n];
    for (int u = 0; u < n; ++u)
      mat[u] = new ll[n];
    dp = new ll[n];
  }
  void change_edge(int u, int v, ll w) {
    mat[u][v] = w;
  }
  ll dfs(int u) {
    if (u == n-1) return 0;
    if (dp[u] != -1)  return dp[u];
    dp[u] = 0;
    for (int v = u+1; v < n; ++v)
      dp[u] = std::max(dp[u], dfs(v) + mat[u][v]);
    return dp[u];
  }
};

int N, M;
std::vector<ll> W;
std::vector<pll> P;

int main() {
  std::cin >> N >> M;
  ll maxw = 0;
  for (int i = 0; i < N; ++i) {
    ll w; std::cin >> w;
    W.push_back(w);
    maxw = std::max(maxw, w);
  }
  std::sort(W.begin(), W.end());

  bool unavoid_collapse = false;

  for (int i = 0; i < M; ++i) {
    ll l, v;  std::cin >> l >> v;
    P.push_back({v, l});
    if (maxw > v)
      unavoid_collapse = true;
  }
  std::sort(P.begin(), P.end());
  segtree *root = new segtree(P, 0, M-1);

  if (unavoid_collapse) {
    std::cout << "-1\n";
    return 0;
  }

  graph g(N);
  ll ans = (1LL << 60);
  do {
    /*for (int w : W)
      std::cout << w << " ";
    std::cout << "\n";*/
    for (int i = 0; i < N; ++i) {
      ll s = W[i];
      for (int j = i+1; j < N; ++j) {
        s += W[j];
        int k = -1;
        for (int jump = M; jump >= 1; jump >>= 1)
          while (k + jump < M and P[k + jump].first < s)
            k += jump;
        //std::cout << i << " " << j << " " << k << "\n";
        g.change_edge(i, j, root->query(0, k));
      }
    }
    for (int u = 0; u < N; ++u) g.dp[u] = -1;
    ll dist = g.dfs(0);
    ans = std::min(ans, dist);
    //std::cout << dist << "\n";
    //std::cout << "-----\n";
  } while (std::next_permutation(W.begin(), W.end()));
  std::cout << ans << "\n";

  return 0;
}
