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 input() {
  int res = 0, m = 1;
  char c = ' ';
  while (c < '0' && c != '-') c = getchar();
  if (c == '-') m = -1, c = getchar();
  while (c >= '0') res = res * 10 + (c - '0'), c = getchar();
  return res * m;
}
const int N = 3e5 + 1;
int d[N];
vector<pair<int, int> > g[N];
vector<int> ans;
char us[N];
void dfs(int u) {
  us[u] = 1;
  for (auto c : g[u]) {
    int v = c.first, id = c.second;
    if (us[v]) continue;
    if (d[v]) {
      cout << ans.size() + 1 << "\n";
      for (auto i : ans) cout << i << "\n";
      cout << id;
      {
        cout << "\n";
        exit(0);
      };
    }
    ans.push_back(id);
    dfs(v);
  }
  ans.pop_back();
}
void dfs2(int u, int p) {
  us[u] = 1;
  for (auto c : g[u]) {
    int v = c.first, id = c.second;
    if (d[v]) continue;
    if (us[v] && v != p) {
      cout << ans.size() + 1 << "\n";
      for (auto i : ans) cout << i << "\n";
      cout << id;
      {
        cout << "\n";
        exit(0);
      };
    }
    if (!us[v]) {
      ans.push_back(id);
      dfs2(v, u);
    }
  }
  ans.pop_back();
}
int main() {
  int n = input(), m = input();
  for (int i = 0; i < n; ++i) {
    d[i] = input();
    if (d[i] == -1) {
      cout << 0;
      exit(0);
    };
  }
  for (int i = 0; i < m; ++i) {
    int u = input() - 1, v = input() - 1;
    g[u].push_back({v, i + 1}), g[v].push_back({u, i + 1});
  }
  for (int i = 0; i < n; ++i)
    if (d[i]) {
      dfs(i);
      break;
    }
  ans.clear();
  for (int i = 0; i < n; ++i) us[i] = 0;
  for (int i = 0; i < n; ++i)
    if (!d[i] && !us[i]) dfs2(i, -1);
  {
    cout << -1;
    exit(0);
  };
}
