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>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fr first
#define sc second
#define ll  long long
#define mp make_pair
#define mod 1000000007

using namespace std;

int n,m;

int a[300300];
int v[303003];
vector<pii>p[300300];

bool dfs(int x){
    while(!p[x].empty()){

        pii t = p[x].back();
        p[x].pop_back();
        if(v[t.sc])continue;
        v[t.sc] = 1;

        if(a[t.fr] == 1){
            a[t.fr] = 0;
            return 1;
        }

        if(a[t.fr] == -1){
            return 1;
        }

        if(dfs(t.fr))return 1;
        v[t.sc] = 0;
    }
    return 0;
}

int main()  {
    cin>>n>>m;
    for(int i=1 ;i<=n ; i++){
        scanf("%d",&a[i]);
    }
    int x,y;
    for(int i=0 ;i <m ;i ++){
        scanf("%d%d",&x,&y);
        p[x].push_back(mp(y,i));
        p[y].push_back(mp(x,i));
    }
    for(int i=1 ;i <=n ;i ++){
        reverse(p[i].begin(),p[i].end());
    }
    for(int i=1; i<=n ; i++){
        if(a[i] == 1){
            if(dfs(i)){
                a[i] = 0;
            }
            else{
                cout<<-1;
                return 0;
            }
        }
    }
    int r= 0;
    for(int i=0 ;i <m ; i++){
        if(v[i]==1)r++;
    }
    cout<<r<<endl;
    for(int i=0 ;i <m ; i++){
        if(v[i]==1)printf("%d ",i+1);
    }

    return 0;
}
