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;
inline long long getnum() {
  char c = getchar();
  long long num, sign = 1;
  for (; c < '0' || c > '9'; c = getchar())
    if (c == '-') sign = -1;
  for (num = 0; c >= '0' && c <= '9';) {
    c -= '0';
    num = num * 10 + c;
    c = getchar();
  }
  return num * sign;
}
vector<int> V[300004];
int E[300004], sel[300004], A[300004];
void dfs(int n) {
  if (A[n] != 1 || V[n].size() == 0) return;
  int e = V[n].back();
  V[n].pop_back();
  int x = E[e] - n;
  sel[e] = 1 - sel[e];
  A[n] = 1 - A[n];
  if (A[x] != -1) A[x] = 1 - A[x];
  dfs(x);
}
int main() {
  int n = getnum(), m = getnum(), pos = 1;
  for (int i = 1; i <= n; i++) A[i] = getnum();
  for (int i = 1; i <= m; i++) {
    int x = getnum(), y = getnum();
    E[i] = x + y;
    V[x].push_back(i);
    V[y].push_back(i);
  }
  for (int i = 1; i <= n; i++)
    if (A[i] == 1) dfs(i);
  for (int i = 1; i <= n; i++)
    if (A[i] == 1) pos = 0;
  if (pos == 0)
    puts("-1");
  else {
    int ans = 0;
    for (int i = 1; i <= m; i++)
      if (sel[i]) ans++;
    printf("%d\n", ans);
    for (int i = 1; i <= m; i++)
      if (sel[i]) printf("%d\n", i);
  }
}
