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 int N = 4 * 1e5;
vector<pair<int, int> > v[N];
bool mark[N];
int d[N];
vector<int> ans;
bool dfs(int x) {
  mark[x] = true;
  bool cnt = false;
  for (int i = 0; i < v[x].size(); i++) {
    int u = v[x][i].first;
    if (!mark[u] && dfs(u)) {
      cnt = !cnt;
      ans.push_back(v[x][i].second);
    }
  }
  cnt ^= d[x];
  return cnt;
}
int main() {
  ios_base::sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  bool has = false, cnt = 0;
  for (int i = 0; i < n; i++) {
    cin >> d[i];
    if (d[i] == -1)
      has = true;
    else if (d[i] == 1)
      cnt = !cnt;
  }
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    v[a].push_back(make_pair(b, i));
    v[b].push_back(make_pair(a, i));
  }
  if (!has && cnt) return cout << -1 << endl, 0;
  for (int i = 0; i < n; i++)
    if (d[i] == -1) {
      if (cnt) {
        cnt = 0;
        d[i] = 1;
      } else
        d[i] = 0;
    }
  dfs(0);
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); i++) cout << ans[i] + 1 << endl;
  return 0;
}
