#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

template <typename T1, typename T2>
inline void chmax(T1 &a, T2 b) {
    if (a < b) a = b;
}

signed main() {
    int n, m;
    cin >> n >> m;
    int mx = 0;
    int w[n];
    rep(i, n) {
        cin >> w[i];
        chmax(mx, w[i]);
    }
    bool flag = false;
    pair<int, int> a[m];
    rep(i, m) {
        cin >> a[i].second >> a[i].first;
        if (a[i].first < mx) flag = true;
    }
    if (flag) {
        cout << -1 << endl;
        return 0;
    }
    sort(a, a + m);
    rep(i, m - 1) {
        chmax(a[i + 1].second, a[i].second);
    }
    int ans = INF;
    vector<int> v(n);
    iota(ALL(v), 0);
    do {
        int ww[n];
        rep(i, n) {
            ww[i] = w[v[i]];
        }
        vector<pair<int, int>> G[n];
        for (int cur = 0; cur < n; cur++) {
            int sum = ww[cur];
            for (int to = cur + 1; to < n; to++) {
                sum += ww[to];
                int idx = lower_bound(a, a + m, pair<int, int>(sum, 0)) - a;
                idx--;
                if (idx < 0)
                    G[cur].emplace_back(to, 0);
                else
                    G[cur].emplace_back(to, a[idx].second);
            }
        }
        int dp[n] = {};
        for (int v = 0; v < n; v++) {
            for (auto p : G[v]) {
                chmax(dp[p.first], dp[v] + p.second);
            }
        }
        ans = min(ans, dp[n - 1]);
    } while (next_permutation(ALL(v)));
    cout << ans << endl;
    return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	if(m==0){
		for(int i=1;i<=n;i++)printf("%d %d\n",2*i,2*i+1);
	}
	else if(m==n||m==-n||m==n-1||m==1-n)printf("-1");
	else{
		int k=5e7;
		if(m>=0){
			printf("%d %d\n",1,k);
			for(int i=1;i<=1+m;i++)printf("%d %d\n",i<<1,i<<1|1);
			for(int i=0;i+m+2<n;i++)printf("%d %d\n",k+i*2+1,k+i*2+2);
		}
		else{
			printf("-1");
/*			m=-m;
			printf("%d %d\n",k,2*k);
			for(int i=1;i<=1+m;i++)printf("%d %d\n",2*k-2*i,2*k-2*i+1);
			for(int i=0;i+m+2<n;i++)printf("%d %d\n",2*i+1,2*i+2);
			*/
		}
	}
}