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;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template<class T> bool chmin(T& a,T b){if(a>b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b){if(a<b) {a = b; return true;} return false;}
#define all(x) (x).begin(),(x).end()
#define debug(x)  cerr << #x << " = " << (x) << endl;

using P = pair<int,int>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,M;
    cin >> N >> M;
    vec<int> D(N);
    for(auto& x:D) cin >> x;
    vvec<P> g(N);
    for(int i=0;i<M;i++){
        int a,b;
        cin >> a >> b;
        a--,b--;
        g[a].emplace_back(b,i);
        g[b].emplace_back(a,i);
    }
    set<int> ans;
    vvec<P> tree(N);
    vec<int> vis(N);
    {
        auto dfs = [&](auto&& self,int cur,int pid)->void{
            vis[cur] = 1;
            for(auto& [to,id]:g[cur]) if(id!=pid){
                if(!vis[to]){
                    self(self,to,id);
                    tree[cur].emplace_back(to,id);
                    tree[to].emplace_back(cur,id);
                }else{
                    ans.insert(id);
                }
            }
        };
        dfs(dfs,0,-1);
    }
    if(find(all(D),-1)==D.end()){
        int sign = accumulate(all(D),0)%2;
        if(sign){
            cout << "-1\n";
            return 0;
        }
    }
    int root = 0;
    for(int i=0;i<N;i++) if(D[i]==-1) root = i;
    {
        auto dfs = [&](auto&& self,int cur,int par,int pid)->int{
            int cnt = cur!=root;
            for(auto& [to,id]:tree[cur]) if(to!=par){
                cnt += self(self,to,cur,id);
                cnt %= 2;
            }
            if(D[cur]==-1) return cnt;
            if(cnt!=D[cur]){
                ans.insert(pid);
                return 0;
            }
            return 1;
        };
        dfs(dfs,root,-1,-1);
    }
    cout << M-(int) ans.size() << "\n";
    for(int i=0;i<M;i++) if(!ans.count(i)) cout << i+1 << "\n";
}