#include <bits/stdc++.h>

#pragma GCC optimize("Ofast")
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
constexpr ll INF = 1e11;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n, m, ans = 0, mx = 0;
  cin >> n >> m;
  vector<ll> w(n), l(m), v(m);
  vector<pair<ll, ll>> p(m);
  rep(i, n) cin >> w[i];
  mx = *max_element(w.begin(), w.end());
  rep(i, m) {
    cin >> l[i] >> v[i];
    if (v[i] < mx) {
      cout << -1 << endl;
      return 0;
    }
    p[i] = {v[i], l[i]};
  }
  sort(p.begin(), p.end());
  for (int i = 1; i < m; ++i) p[i].second = max(p[i].second, p[i - 1].second);
  ll mn = 1 << 30;
  vector<int> a;
  rep(i, n) a.push_back(i);
  ll d[10][10];

  do {
    rep(i, 10) rep(j, 10) d[i][j] = 0;
    rep(i, n) {
      ll ls = 0;
      for (int j = i; j < n; ++j) {
        ls += w[a[j]];
        ll t = lower_bound(p.begin(), p.end(), make_pair(ls, 0ll)) - p.begin();
        if (t) d[i][j] = max(d[i][j], p[t - 1].second);
      }
    }
    rep(i, 8) rep(x, n) for (int z = x + 1; z < n;
                             ++z) for (int y = z + 1; y < n; ++y) d[x][y] =
        max(d[x][y], d[x][z] + d[z][y]);
    mn = min(mn, d[0][n - 1]);
  } while (next_permutation(a.begin(), a.end()));

  cout << mn << endl;
  return 0;
}

// Author: Muhesh Kumar

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ull = unsigned long long;
using db = long double;
using pi = pair<int, int>;
using pl = pair<ll, ll>;

using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using vs = vector<string>;
using vpi = vector<pi>;
using vpl = vector<pl>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using vvb = vector<vb>;

#define nl '\n'
#define fr first
#define sc second
#define bk back()
#define ft front()
#define pb push_back
#define ppb pop_back
#define lb lower_bound
#define ub upper_bound
#define bg(x) begin(x)
#define all(x) bg(x), end(x)
#define sz(x) (int) (x).size()
#define amax(a, b) a = max(a, b)
#define amin(a, b) a = min(a, b)
#define trav(a, b) for(auto &a: b)
#define rep(i, a, b) for(int i = a; i < b; i++)

const ll inf = 1e18 + 10;
const db eps = 1e-9;
const int mod = 1e9 + 7;

ll modadd(ll a, ll b, ll m = mod) { a %= m; b %= m; return (((a + b) % m) + m) % m; }
ll modsub(ll a, ll b, ll m = mod) { a %= m; b %= m; return (((a - b) % m) + m) % m; }
ll modmul(ll a, ll b, ll m = mod) { a %= m; b %= m; return (((a * b) % m) + m) % m; }
ll gcd(ll a, ll b) { return __gcd(a, b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

template <typename T1, typename T2> 
inline std::ostream &operator << (std::ostream& os, const std::pair<T1, T2>& p) { 
    return os << "(" << p.first << ", " << p.second << ")"; 
} 

template<typename T> 
inline std::ostream &operator << (std::ostream& os,const std::vector<T>& v) { 
    bool first = true; 
    os << "["; 
    for(unsigned int i = 0; i < v.size(); i++) { 
        if(!first) 
            os << ", "; 
        os << v[i]; 
        first = false; 
    } 
    return os << "]"; 
} 

template<typename T> 
inline std::ostream &operator << (std::ostream& os,const std::vector<vector<T>>& v) { 
    bool first = true; 
    os << "[\n "; 
    for(unsigned int i = 0; i < v.size(); i++) { 
        if(!first) 
            os << ",\n "; 
        os << v[i]; 
        first = false; 
    } 
    return os << "\n]"; 
} 

template<typename T> 
inline std::ostream &operator << (std::ostream& os,const std::set<T>& v) { 
    bool first = true; 
    os << "["; 
    for (typename std::set<T>::const_iterator ii = v.begin(); ii != v.end(); ++ii) { 
        if(!first) 
            os << ", "; 
        os << *ii; 
        first = false; 
    } 
    return os << "]"; 
} 

template<typename T1, typename T2> 
inline std::ostream &operator << (std::ostream& os,const std::map<T1, T2>& v) { 
    bool first = true; 
    os << "[\n "; 
    for (typename std::map<T1, T2>::const_iterator ii = v.begin(); ii != v.end(); ++ii) { 
        if(!first) 
            os << ",\n "; 
        os << *ii ; 
        first = false; 
    } 
    return os << "\n]"; 
}

#ifndef ONLINE_JUDGE
    #define debug(a) cerr << #a << " " << a << '\n';
#else
    #define debug(a)
#endif

int main() {
 
    ios::sync_with_stdio(false);
    cin.tie(0);

    int N; cin >> N;
    vl v(N);
    trav (i, v) cin >> i;

    int n = 8;
    if (N < 8)
        n = N;

    map<int, vi> sum_seqs;
    rep(mask, 0, 1 << n) {
        vi seq;
        ll sum = 0;
        rep(i, 0, n) {
            if (mask & (1 << i)) {
                seq.pb(i);
                sum += v[i];
            }
        }

        sum %= 200;

        if (!sum_seqs[sum].empty()) {
            vi other_seq = sum_seqs[sum];
            
            cout << "Yes" << nl;
            cout << sz(other_seq) << " ";
            trav (j, other_seq) cout << j + 1 << " ";
            cout << nl;

            cout << sz(seq) << " ";
            trav (j, seq) cout << j + 1 << " ";
            cout << nl;

            return 0;
        }

        sum_seqs[sum] = seq;
    }

    cout << "No";

    return 0;
}