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 <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <set>

using namespace std;

const int maxn = 3e5+10;
typedef pair<int,int> Edge;

Edge fa[maxn];
int n,m,node;
int d[maxn];
vector<Edge>mp[maxn];
bool vis[maxn],select[maxn];

void dfs(int u,int pre)
{
    int v,id;
    int num = mp[u].size();
    for(int i = 0;i < num; i++) {
        v = mp[u][i].first;
        id = mp[u][i].second;
        if(v == pre || vis[v]) continue;
        vis[v] = true;
        fa[v] = Edge(u,id);
        dfs(v,u);
        if(d[v] == 1) {
            select[id] ^= 1;
            d[v] = true;
            if(d[u] != -1) {
                d[u] ^= 1;
            }
        }
    }
}

int main()
{
//    freopen("in.txt","r",stdin);
    scanf("%d%d",&n,&m);
    for(int i = 1;i <= n; i++) {
        scanf("%d",d+i);
        if(d[i] == -1) node = i;
    }
    for(int i = 1;i <= m; i++) {
        int u,v;
        scanf("%d%d",&u,&v);
        mp[u].push_back(Edge(v,i));
        mp[v].push_back(Edge(u,i));
    }


    dfs(1,-1);
    if(d[1] == 1) {
        if(node == 0) {
            printf("-1\n");
            return 0;
        }
        else {
            while(node != 1) {
                select[fa[node].second] ^= 1;
                node = fa[node].first;
            }
        }
    }
    int ans = 0;
    for(int i = 1;i <= m; i++) {
        if(select[i]) ans++;
    }
    printf("%d\n",ans);
    for(int i = 1;i <= m; i++) {
        if(select[i]) {
            printf("%d ",i);
        }
    }
    printf("\n");
    return 0;
}
