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>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

#define ll long long
#define M 300007
#define MOD 1000000007

// Order Statistic Tree

/* Special functions:

        find_by_order(k) --> returns iterator to the kth largest element counting from 0
        order_of_key(val) --> returns the number of items in a set that are strictly smaller than our item
*/

typedef tree<
ll,					// type long long
null_type,
less<ll>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;



/////// THIS VIOLENT DELIGHTS HAVE VIOLENT ENDS //////////
int d[M];
int deg[M];
vector< int >ed[M];
pair< int, int >nm[M];
int tk[M];
int vs[M];

int main(void)
{
    std::ios::sync_with_stdio(false);
    int n, m, u, v, i, j, e, ans;
    cin >> n >> m;
    for (i = 1; i <= n; i++) cin >> d[i];
    for (i = 1; i <= m; i++) {
        cin >> nm[i].first >> nm[i].second;
        ed[nm[i].first].push_back(i);
        ed[nm[i].second].push_back(i);
        deg[nm[i].first]++;
        deg[nm[i].second]++;
        tk[i] = 1;
    }
    queue< int >q;
    q.push(1);
    ans = m;
    while (!q.empty()) {
        u = q.front();
        q.pop();
        vs[u] = 1;
        //cout << u << endl;
        if (d[u]>=0&&deg[u]%2!=d[u]) {
            for (i = 0; i < ed[u].size(); i++) {
                e = ed[u][i];
                v = nm[e].first;
                if (u==v) v = nm[e].second;
                if (d[v]==-1||(d[v]!=deg[v]%2&&tk[e])) {
                    //cout << "remove " << e << endl;
                    tk[e] = 0;
                    deg[u]--;
                    deg[v]--;
                    ans--;
                    break;
                }
            }
            if (deg[u]%2!=d[u]) {
                cout << -1 << endl;
                return 0;
            }
        }
        for (i = 0; i < ed[u].size(); i++) {
            e = ed[u][i];
            v = nm[e].first;
            if (u==v) v = nm[e].second;
            if (vs[v]) continue;
            q.push(v);
        }
    }

    for (i = 1; i <= n; i++) {
        //cout << i << ' ' << deg[i] << endl;
        if (d[i]>=0&&d[i]!=deg[i]%2) {
            cout << -1 << endl;
            return 0;
        }
    }

    cout << ans << endl;
    for (i = 1; i <= m; i++) if (tk[i]) cout << i << endl;

    return 0;
}

