#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma,avx512f,avx512bw,avx512bitalg")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

//雪花飄飄北風嘯嘯
//天地一片蒼茫

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << " is " << x << endl

#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define lb lower_bound
#define ub upper_bound

#define rep(x,start,end) for(int x=start;x!=end;x++)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()

#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
//change less to less_equal for non distinct pbds, but erase will bug

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

int B,m;
bool bad[25][25];

int ind[1050000];

int ahat[1050000][21];
int bhat[1050000][21];
ll hat[1050000][21];

void conv(){
	for (int x=0;x<1048576;x++) {
		ahat[x][__builtin_popcount(x)]=ind[x];
		bhat[x][__builtin_popcount(x)]=ind[x];
	}
	
	rep(bit,0,20){
		for (int x=0;x<1048576;x++) if (x&(1<<bit)){
			rep(cnt,0,21){
				ahat[x][cnt]+=ahat[x^(1<<bit)][cnt];
				bhat[x][cnt]+=bhat[x^(1<<bit)][cnt];
			}
		}
	}
	
	for (int x=0;x<1048576;x++){
		rep(cnt,0,21){
			rep(cnt2,0,cnt+1){
				hat[x][cnt]+=(ll)ahat[x][cnt2]*bhat[x][cnt-cnt2];
			}
		}
	}
	
	
	rep(bit,0,20){
		for (int x=0;x<1048576;x++) if (x&(1<<bit)){
			rep(cnt,0,21){
				hat[x][cnt]-=hat[x^(1<<bit)][cnt];
			}
		}
	}
	
    memset(ahat,0,sizeof(ahat));
	memset(bhat,0,sizeof(bhat));
	
	for (int x=0;x<1048576;x++){
		ahat[x][__builtin_popcount(x)]=ind[x];
		bhat[x][__builtin_popcount(x)]=hat[x][__builtin_popcount(x)];
	}
	
	memset(hat,0,sizeof(hat));
	
	rep(bit,0,20){
		for (int x=0;x<1048576;x++) if (x&(1<<bit)){
			rep(cnt,0,21){
				ahat[x][cnt]+=ahat[x^(1<<bit)][cnt];
				bhat[x][cnt]+=bhat[x^(1<<bit)][cnt];
			}
		}
	}
	
	for (int x=0;x<1048576;x++){
		rep(cnt,0,21){
			rep(cnt2,0,cnt+1){
				hat[x][cnt]+=(ll)ahat[x][cnt2]*bhat[x][cnt-cnt2];
			}
		}
	}
	
	
	rep(bit,0,20){
		for (int x=0;x<1048576;x++) if (x&(1<<bit)){
			rep(cnt,0,21){
				hat[x][cnt]-=hat[x^(1<<bit)][cnt];
			}
		}
	}
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin.exceptions(ios::badbit | ios::failbit);
	
	cin>>B>>m;
	
	int a,b;
	rep(x,0,m){
		cin>>a>>b;
		a--,b--;
		bad[a][b]=bad[b][a]=true;
	}
	
	ind[0]=1;
	rep(x,1,1<<B){
		int temp=__builtin_ctz(x);
		int nx=x^(1<<temp);
		
		ind[x]=ind[nx];
		
		rep(bit,0,B) if (nx&(1<<bit) && bad[temp][bit]){
			ind[x]=0;
		}
	}
	
	conv();
	
	cout<<hat[(1<<B)-1][B]<<endl;
}

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

using ll = long long;
using pii = pair<int, int>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define per(i, b) per2(i, 0, b)
#define per2(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define ALL(c) (c).begin(), (c).end()
#define SZ(x) ((int)(x).size())

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }

template <class T, class U>
void chmin(T& t, const U& u) {
    if (t > u) t = u;
}
template <class T, class U>
void chmax(T& t, const U& u) {
    if (t < u) t = u;
}

template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "{";
    rep(i, v.size()) {
        if (i) os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

#ifdef LOCAL
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << H;
    debug_out(T...);
}
#define debug(...) \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

const ll INF = TEN(18);

int main() {
    int N, M;
    cin >> N >> M;
    V<ll> w(N);
    rep(i, N) cin >> w[i];

    V<int> pm(N);
    iota(ALL(pm), 0);
    V<pii> br(M);
    ll mx = 0;

    for (auto v : w) chmax(mx, v);
    rep(i, M) cin >> br[i].se >> br[i].fi;
    rep(i, M) if (mx > br[i].fi) {
        puts("-1");
        return 0;
    }

    map<int, int> D;

    int now = 0;
    V<int> xs;
    rep(i, 1 << N) {
        int s = 0;
        rep(j, N) if (i >> j & 1) { s += w[j]; }
        xs.pb(s);
    }
    sort(ALL(xs));
    sort(ALL(br));
    int md = 0;
    for (auto v : xs) {
        while (now < M && br[now].fi < v) {
            chmax(md, br[now++].se);
        }
        D[v] = md;
    }

    ll ans = INF;
    do {
        V<ll> a(N);
        rep(i, N) a[i] = w[pm[i]];
        V<ll> dp(N);

        rep(i, N) {
            int s = 0;
            if (i) chmax(dp[i], dp[i - 1]);
            for (int j = i; j < N; ++j) {
                s += a[j];
                if (j > i) chmax(dp[j], dp[i] + D[s]);
            }
        }
        chmin(ans, dp.back());
    } while (next_permutation(ALL(pm)));
    cout << ans << endl;
    return 0;
}