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>


using namespace std;

typedef pair<int,int> p;

vector<p> mp[300005];


int a[300005];
p fa[300005];
bool vis[300005];

bool select[300005];

void dfs(int x,int pre) {

     for(int i=0;i<mp[x].size();i++) {
        int v = mp[x][i].first;
        int id=mp[x][i].second;
        if(vis[v] || x==pre) continue;

        vis[v]=1;
        fa[v] = p(x, id);

        dfs(v,x);

        if(a[v]==1) {
            a[v]=0;
            select[id]^=1;
            if(a[x]!=-1) {
                a[x]^=1;
            }

        }
     }


}
int main() {

    int n,m;
    cin>>n>>m;
    int x,y;
    int flag=0;
    int chose;
    for(int i=1;i<=n;i++) {
        scanf("%d",&a[i]);
        if(a[i]==-1) {
           flag=1;
        }
    }

    for(int i=1;i<=m;i++) {
        scanf("%d%d",&x,&y);
        mp[x].push_back(p(y,i));
        mp[y].push_back(p(x,i));


    }

    for(int i=0;i<=n;i++) {
        vis[i]=0;
        select[i]=0;
    }
    dfs(1,-1);

    if(a[1] == 1)
    {
        if(flag == 0)
        {
            cout << -1;
            return 0;
        }
        while(flag != 1)
        {
            select[fa[flag].second] ^= 1;
            flag = fa[flag].first;
        }
    }

    int cnt=0;
    for(int i=1;i<=m;i++) {
        if(select[i])
         cnt++;
    }

    cout<<cnt<<endl;
    for(int i=1;i<=m;i++)  {
        if(select[i]) {
            cout<<i<<endl;
        }

    }





 return 0;
}

