3 2
1 0 1
1 2
2 3
 10 10
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1
6 7
8 3
6 4
4 2
9 2
5 10
9 8
10 7
5 1
6 2

2
1
2
 0

#include <bits/stdc++.h>
#include <ext/rope>
#define sz(x) (int)x.size()
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define mp make_pair
using namespace std;
using namespace __gnu_cxx;
typedef long long ll;
const ll oo = 1e18;
const int N = 300100;
const int M = 50100;
vector<pii> g[N];
vector<int> ans;
int n,m,d[N],ed[N],pr[N],kl[N];
bool mrk[N];

void dfs(int v){
    mrk[v]=1;
    for (pii u : g[v]){
        if (mrk[u.F]) continue;
        ed[u.F]=u.S; pr[u.F]=v;
        dfs(u.F);
    }
    if (pr[v]>=0){
        if (d[v]==0){
            if (kl[v]&1){
                ans.pb(ed[v]); kl[pr[v]]++;
            }
        } else {
            if (!(kl[v]&1)){
                ans.pb(ed[v]); kl[pr[v]]++;
            }
        }
    }
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(NULL);
//    freopen("milkorder.in","r",stdin); freopen("milkorder.out","w",stdout);
    srand(time(0));
    cin>>n>>m;
    for (int i=0;i<n;i++) cin>>d[i];
    for (int i=1;i<=m;i++){
        int x,y; cin>>x>>y; x--; y--;
        g[x].pb(mp(y,i)); g[y].pb(mp(x,i));
    }
    ans.clear();
    for (int i=0;i<n;i++)
        if (d[i]<0){
            pr[i]=-1; dfs(i);
            cout<<sz(ans)<<'\n';
            for (int x : ans) cout<<x<<'\n';
            return 0;
        }
    for (int i=0;i<100;i++){
        int nm=((rand()<<10)+rand())%n;
        pr[nm]=-1; dfs(nm);
        if (kl[nm]==d[nm]){
            cout<<sz(ans)<<'\n';
            for (int x : ans) cout<<x<<'\n';
            return 0;
        }
    }
    cout<<-1;
    return 0;
}
