#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<pll> vpl;
#define pb push_back
#define MAXN 200005
const ll N=32;
#define INF (ll)1e18
#define mod 1000000007
//#define mod 998244353
#define fi first
#define se second
#define mkp make_pair
#define clr(v) v.clear()
#define sze(x) ((ll)x.size())
#define all(v) v.begin(),v.end()
#define endl '\n'
#define level 20
ll timer,cc1,cc;
void boost()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
ll a[MAXN],deg[MAXN];
ll par[MAXN];
set<pll,greater<pll>> ss[MAXN];
ll fp(ll i)
{
if(par[par[i]]!=par[i])
par[i]=fp(par[i]);
return par[i];
}
void join(ll a,ll b)
{
ll j,k;
j=fp(a);
k=fp(b);
if(j==k)
return;
if(sze(ss[j])>=sze(ss[k]))
swap(j,k);
par[j]=k;
for(auto x :ss[j])
{
ss[k].insert(x);
}
return;
}
int main()
{
boost();
ll i,t,q,l,r,ans,mid,c=0,j,z,tc,n,k;
ll h,m,u,mm,w,x,y,l1,r1,d=0,mask,v,mx;
ld f,f1;
cin>>n>>m;
vpl g;
for(i=1;i<=n;i++)
{
cin>>a[i];
par[i]=i;
}
priority_queue<pair<pll,ll>> pq;
for(i=0;i<m;i++)
{
cin>>x>>y;
deg[x]++;
deg[y]++;
if(fp(x)!=fp(y))
join(x,y);
else
c++;
}
l=0;
for(i=1;i<=n;i++)
{
if(deg[i]>a[i])
{
c++;
}
d+=a[i];
l+=a[i]-deg[i];
}
z=(d/2);
q=n-m-1;
if((c>0)||(d&1)||(z!=(n-1))||(l!=(2*q)))
cout<<-1<<endl;
else
{
for(i=1;i<=n;i++)
{
l=fp(i);
z=a[i]-deg[i];
if(z>0)
ss[l].insert(mkp(z,i));
}
for(i=1;i<=n;i++)
{
if(fp(i)==i)
{
if(sze(ss[i])>0)
{
auto p=*ss[i].begin();
ss[i].erase(ss[i].begin());
pq.push(mkp(p,i));
}
}
}
while(q--)
{
if(sze(pq)==0)
{
c++;
break;
}
auto p1=pq.top();
pq.pop();
if(sze(pq)==0)
{
c++;
break;
}
auto p2=pq.top();
pq.pop();
l=p1.se;
r=p2.se;
if(p1.fi.fi-1>0)
ss[l].insert(mkp(p1.fi.fi-1,p1.fi.se));
if(p2.fi.fi-1>0)
ss[r].insert(mkp(p2.fi.fi-1,p2.fi.se));
g.pb(mkp(p1.fi.se,p2.fi.se));
join(l,r);
y=fp(l);
if(sze(ss[y])>0)
{
auto p=*ss[y].begin();
ss[y].erase(ss[y].begin());
pq.push(mkp(p,y));
}
}
if(c>0||sze(pq)>0)
cout<<-1<<endl;
else
{
for(auto x :g)
cout<<x.fi<<" "<<x.se<<endl;
}
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiAKdHlwZWRlZiBsb25nIGxvbmcgbGw7CnR5cGVkZWYgbG9uZyBkb3VibGUgbGQ7CnR5cGVkZWYgcGFpcjxsbCxsbD4gcGxsOwp0eXBlZGVmIHZlY3RvcjxsbD4gdmw7CnR5cGVkZWYgdmVjdG9yPHBsbD4gdnBsOwojZGVmaW5lIHBiIHB1c2hfYmFjawojZGVmaW5lIE1BWE4gMjAwMDA1CmNvbnN0IGxsIE49MzI7CiNkZWZpbmUgSU5GIChsbCkxZTE4CiNkZWZpbmUgbW9kIDEwMDAwMDAwMDcKLy8jZGVmaW5lIG1vZCA5OTgyNDQzNTMKI2RlZmluZSBmaSBmaXJzdAojZGVmaW5lIHNlIHNlY29uZAojZGVmaW5lIG1rcCBtYWtlX3BhaXIKI2RlZmluZSBjbHIodikgdi5jbGVhcigpCiNkZWZpbmUgc3plKHgpICgobGwpeC5zaXplKCkpCiNkZWZpbmUgYWxsKHYpIHYuYmVnaW4oKSx2LmVuZCgpCiNkZWZpbmUgZW5kbCAnXG4nCiNkZWZpbmUgbGV2ZWwgMjAKbGwgdGltZXIsY2MxLGNjOwoKdm9pZCBib29zdCgpCnsKIGlvc19iYXNlOjpzeW5jX3dpdGhfc3RkaW8oZmFsc2UpOwogY2luLnRpZShOVUxMKTsKfQoKbGwgYVtNQVhOXSxkZWdbTUFYTl07CgpsbCBwYXJbTUFYTl07CnNldDxwbGwsZ3JlYXRlcjxwbGw+PiBzc1tNQVhOXTsKCiAKbGwgZnAobGwgaSkKewogICAgaWYocGFyW3BhcltpXV0hPXBhcltpXSkKICAgIHBhcltpXT1mcChwYXJbaV0pOwogICAgCiAgICByZXR1cm4gcGFyW2ldOwp9CiAKdm9pZCBqb2luKGxsIGEsbGwgYikKewogICAgbGwgaixrOwogICAgCiAgICBqPWZwKGEpOwogICAgaz1mcChiKTsKICAgIAogICAgaWYoaj09aykKICAgIHJldHVybjsKICAgIAogICAgCiAgICBpZihzemUoc3Nbal0pPj1zemUoc3Nba10pKQogICAgc3dhcChqLGspOwogICAgCiAgICAKICAgIHBhcltqXT1rOwogICAgZm9yKGF1dG8geCA6c3Nbal0pCiAgICB7CiAgICAgICAgc3Nba10uaW5zZXJ0KHgpOwogICAgfQogICAgCiAgICByZXR1cm47Cn0KCmludCBtYWluKCkKewogYm9vc3QoKTsKICAKIGxsIGksdCxxLGwscixhbnMsbWlkLGM9MCxqLHosdGMsbixrOwogbGwgaCxtLHUsbW0sdyx4LHksbDEscjEsZD0wLG1hc2ssdixteDsKIGxkIGYsZjE7CiAKIGNpbj4+bj4+bTsKIHZwbCBnOwogCiBmb3IoaT0xO2k8PW47aSsrKQogewogY2luPj5hW2ldOwogcGFyW2ldPWk7CiB9CiAKIHByaW9yaXR5X3F1ZXVlPHBhaXI8cGxsLGxsPj4gcHE7CiAKIGZvcihpPTA7aTxtO2krKykKIHsKICAgICBjaW4+Png+Pnk7CiAgICAgZGVnW3hdKys7CiAgICAgZGVnW3ldKys7CiAgICAgCiAgICAgaWYoZnAoeCkhPWZwKHkpKQogICAgIGpvaW4oeCx5KTsKICAgICAKICAgICBlbHNlCiAgICAgYysrOwogICAgIAogfQogCiBsPTA7CiBmb3IoaT0xO2k8PW47aSsrKQogewogICAgIGlmKGRlZ1tpXT5hW2ldKQogICAgIHsKICAgICAgICAgYysrOwogICAgIH0KICAgICAKICAgICBkKz1hW2ldOwogICAgIGwrPWFbaV0tZGVnW2ldOwogfQogCiB6PShkLzIpOwogcT1uLW0tMTsKIAogaWYoKGM+MCl8fChkJjEpfHwoeiE9KG4tMSkpfHwobCE9KDIqcSkpKQogY291dDw8LTE8PGVuZGw7CiAKIGVsc2UKIHsKICAgICBmb3IoaT0xO2k8PW47aSsrKQogICAgIHsKICAgICAgICAgbD1mcChpKTsKICAgICAgICAgej1hW2ldLWRlZ1tpXTsKICAgICAgICAgCiAgICAgICAgIGlmKHo+MCkKICAgICAgICAgc3NbbF0uaW5zZXJ0KG1rcCh6LGkpKTsKICAgICB9CiAgICAgCiAgICAgZm9yKGk9MTtpPD1uO2krKykKICAgICB7CiAgICAgICAgIGlmKGZwKGkpPT1pKQogICAgICAgICB7CiAgICAgICAgICAgIGlmKHN6ZShzc1tpXSk+MCkKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgYXV0byBwPSpzc1tpXS5iZWdpbigpOwogICAgICAgICAgICAgICAgc3NbaV0uZXJhc2Uoc3NbaV0uYmVnaW4oKSk7CiAgICAgICAgICAgICAgICBwcS5wdXNoKG1rcChwLGkpKTsKICAgICAgICAgICAgfQogICAgICAgICB9CiAgICAgfQogICAgIAogICAgIAogICAgIHdoaWxlKHEtLSkKICAgICB7CiAgICAgICAgIGlmKHN6ZShwcSk9PTApCiAgICAgICAgIHsKICAgICAgICAgYysrOwogICAgICAgICBicmVhazsKICAgICAgICAgfQogICAgICAgICAKICAgICAgICAgYXV0byBwMT1wcS50b3AoKTsKICAgICAgICAgcHEucG9wKCk7CiAgICAgICAgIAogICAgICAgICAKICAgICAgICAgaWYoc3plKHBxKT09MCkKICAgICAgICAgewogICAgICAgICBjKys7CiAgICAgICAgIGJyZWFrOwogICAgICAgICB9CiAgICAgICAgIAogICAgICAgICBhdXRvIHAyPXBxLnRvcCgpOwogICAgICAgICBwcS5wb3AoKTsKICAgICAgICAgCiAgICAgICAgIGw9cDEuc2U7CiAgICAgICAgIHI9cDIuc2U7CiAgICAgICAgIAogICAgICAgICBpZihwMS5maS5maS0xPjApCiAgICAgICAgIHNzW2xdLmluc2VydChta3AocDEuZmkuZmktMSxwMS5maS5zZSkpOwogICAgICAgICAKICAgICAgICAgaWYocDIuZmkuZmktMT4wKQogICAgICAgICBzc1tyXS5pbnNlcnQobWtwKHAyLmZpLmZpLTEscDIuZmkuc2UpKTsKICAgICAgICAgCiAgICAgICAgIGcucGIobWtwKHAxLmZpLnNlLHAyLmZpLnNlKSk7CiAgICAgICAgIAogICAgICAgICBqb2luKGwscik7CiAgICAgICAgIHk9ZnAobCk7CiAgICAgICAgIAogICAgICAgICBpZihzemUoc3NbeV0pPjApCiAgICAgICAgIHsKICAgICAgICAgICAgIGF1dG8gcD0qc3NbeV0uYmVnaW4oKTsKICAgICAgICAgICAgIHNzW3ldLmVyYXNlKHNzW3ldLmJlZ2luKCkpOwogICAgICAgICAgICAgcHEucHVzaChta3AocCx5KSk7CiAgICAgICAgIH0KICAgICAgICAgCiAgICAgfQogICAgIAogICAgIGlmKGM+MHx8c3plKHBxKT4wKQogICAgIGNvdXQ8PC0xPDxlbmRsOwogICAgIAogICAgIGVsc2UKICAgICB7CiAgICAgICAgIGZvcihhdXRvIHggOmcpCiAgICAgICAgIGNvdXQ8PHguZmk8PCIgIjw8eC5zZTw8ZW5kbDsKICAgICB9CiB9CgpyZXR1cm4gMDsKfQ==