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;
const long long maxn = 3000 * 100 + 5;
bool mrk[maxn], a[maxn];
long long d[maxn];
vector<long long> aj[maxn], ind[maxn];
set<long long> ans;
void dfs(long long v) {
  mrk[v] = true;
  for (long long i = 0; i < (long long)(aj[v]).size(); i++) {
    long long u = aj[v][i];
    if (!mrk[u]) {
      dfs(u);
      if (d[u] != -1 and d[u] != a[u]) {
        a[u] = !a[u];
        a[v] = !a[v];
        ans.insert(ind[v][i]);
      }
    }
  }
  return;
}
int32_t main() {
  long long n, m, x = 0;
  cin >> n >> m;
  for (long long i = 0; i < n; i++) {
    cin >> d[i];
    if (d[i] == -1) x = i;
  }
  for (long long i = 0; i < m; i++) {
    long long u, v;
    cin >> u >> v;
    u--;
    v--;
    aj[u].push_back(v);
    aj[v].push_back(u);
    ind[u].push_back(i + 1);
    ind[v].push_back(i + 1);
  }
  for (long long i = 0; i < n; i++) a[i] = (long long)(aj[i]).size() % 2;
  dfs(x);
  if (d[x] != -1 and d[x] != a[x])
    cout << -1 << endl;
  else {
    cout << m - (long long)(ans).size() << endl;
    for (long long i = 1; i <= m; i++) {
      if (ans.find(i) == ans.end()) cout << i << ' ';
    }
  }
  return false;
}
