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;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pl;

#define sl(x) scanf("%lld",&x)
#define pl(x) printf("%lld\n",x)
#define sz(x) ((int)x.size())
#define s(x) sort(x.begin(),x.end())
#define all(v) v.begin(),v.end()
#define rs(v) { s(v) ; r(v) ; }
#define r(v) {reverse(all(v));}
#define pb push_back
#define F first
#define S second
#define f(i,n) for(int i=0;i<n;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)

const ll mod = 1000000007;
const ll inf = (ll)5e16;
const ld eps = 1e-12;
const ll N = 1000005;
const ll LOGN = 19;
const ld PI = 3.14159265358979323846;
ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
ll add(ll a, ll b, ll m = mod) { a += b; if(a >= m) a -= m; if(a < 0) a += m; return a;}
ll power(ll a, ll b, ll m = mod) { if(b == 0) return 1; if(b == 1) return (a % m); ll x = power(a, b / 2, m); x = mul(x, x, m); if(b % 2) x = mul(x, a, m); return x;}
ll m, n, d[N], bad[N], any[N], deg[N], rem[N];
set < ll > g[N];
vector < pl > edges;
set < ll > vis;
set < ll > tmp;
bool dfs(ll u, ll o)
{
    if(o != u && (bad[u] || any[u]))
    {
        if(bad[u]) bad[u] = 0;
        if(any[u]) any[u] = 0;
     //   cout << u << " YO\n";
        return true;
    }
    vis.insert(u);
   // cout << u << "\n";
    for(ll ind : g[u])
    {
        ll v = edges[ind].F ^ edges[ind].S ^ u;
        if(vis.find(v) != vis.end()) continue;
        tmp.insert(ind);
        if(dfs(v, o)) return true;
        tmp.erase(ind);
    }
    return false;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin >> n >> m;
    f(i, n) cin >> d[i + 1];
    f(i, m)
    {
        ll u, v;
        cin >> u >> v;
        g[u].insert(i);
        g[v].insert(i);
        edges.pb({u, v});
        deg[u]++;
        deg[v]++;
    }
    vector < ll > a, b;
    ll ta = 0, tb = 0;
    rep(i, 1, n)
    {
        if(d[i] == -1)
        {
            any[i] = 1;
            ta++;
            a.pb(i);
        }
        else if(d[i] == 0 && deg[i] % 2 == 1)
        {
            bad[i] = 1;
            tb++;
            b.pb(i);
        }
        else if(d[i] == 1 && deg[i] % 2 == 0)
        {
            bad[i] = 1;
            tb++;
            b.pb(i);
        }
    }
    if(ta == 0 && tb % 2)
    {
        cout << "-1\n";
        return 0;
    }
    for(ll i = 1; i <= n; i++)
    {
        if(!bad[i]) continue;
        vis.clear();

       // cout << i << "\n";
        dfs(i, i);
       // cout << "\n";
        bad[i] = 0;
        for(ll ind : tmp)
        {
            rem[ind] = 1;
        //    cout << ind << " ";
            ll u = edges[ind].F;
            ll v = edges[ind].S;
            g[u].erase(ind);
            g[v].erase(ind);
        }
      //  cout << "\n";
        tmp.clear();
    }
    vector < ll > ans;
    f(i, m)
    {
        if(!rem[i]) ans.pb(i + 1);
    }
    cout << ans.size() << "\n";
    for(ll x : ans) cout << x << "\n";
    return 0;
}
