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;
int n, m, d[333333], x, y, f, cnt, kk, mx, lto;
vector<int> ans;
vector<pair<int, int> > g[333333];
set<pair<int, int> > pq;
bool used[333333];
void dfs1(int i, int fa, int ed) {
  used[i] = 1;
  for (int j = 0; j < g[i].size(); j++) {
    int to = g[i][j].first;
    if (used[to]) continue;
    dfs1(to, i, g[i][j].second);
  }
  if (d[i] == 1) {
    ans.push_back(ed);
    if (d[fa] == -1) return;
    d[fa] = 1 - d[fa];
    d[i] = 0;
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &d[i]);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &x, &y);
    g[x].push_back(make_pair(y, i));
    g[y].push_back(make_pair(x, i));
  }
  for (int i = 1; i <= n; i++) {
    if (d[i] == -1) f = i;
  }
  if (f) {
    dfs1(f, 0, 0);
    sort(ans.begin(), ans.end());
    printf("%d\n", ans.size());
    for (int i = 0; i < ans.size(); i++) {
      printf("%d\n", ans[i]);
    }
  } else {
    for (int i = 1; i <= n; i++) {
      if (d[i]) {
        cnt++;
        int t = g[i].size();
        pq.insert(make_pair(t, i));
      }
    }
    if (cnt & 1)
      printf("-1\n");
    else {
      if (!cnt)
        printf("0\n");
      else {
        while (!pq.empty()) {
          int x = pq.begin()->second;
          pq.erase(pq.begin());
          cnt = 0;
          for (int i = 0; i < g[x].size(); i++) {
            int to = g[x][i].first;
            if (d[to]) {
              cnt++;
              int t = g[to].size();
              pq.erase(pq.find(make_pair(t, to)));
              ans.push_back(g[x][i].second);
              lto = to;
              d[to] = 0;
            }
          }
          if (!cnt) {
            ans.push_back(g[x][0].second);
            d[g[x][0].first] = 1;
            int to = g[x][0].first, t = g[to].size();
            pq.insert(make_pair(t, to));
          } else if (cnt % 2 == 0) {
            int t = g[lto].size();
            d[lto] = 1;
            pq.insert(make_pair(t, lto));
            ans.pop_back();
          }
          if (ans.size() > m) {
            printf("-1\n");
            return 0;
          }
          d[x] = 0;
        }
        sort(ans.begin(), ans.end());
        printf("%d\n", ans.size());
        for (int i = 0; i < ans.size(); i++) {
          printf("%d\n", ans[i]);
        }
      }
    }
  }
  return 0;
}
