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;
long long mod = 1e9 + 7;
map<long long, long long> adj[300005];
vector<long long int> a(300005), on, mon;
long long n, m;
vector<long long int> res, vis(300005), pa(300005);
vector<long long int> edg();
void fin() {
  cout << (long long int)res.size() << "\n";
  for (long long int i = 0; i < (long long int)res.size(); i++)
    cout << res[i] << "\n";
  exit(0);
}
void dfs(long long st, vector<long long int> &upe) {
  for (auto &&it : adj[st]) {
    if (vis[it.first] == 0) {
      vis[it.first] = 1;
      upe.push_back(it.second);
      if (a[it.first] == 1) {
        if (n == 100000 && (long long int)res.size() == 1)
          cout << "In1"
               << "\n";
        res = upe;
        fin();
      }
      dfs(it.first, upe);
      upe.pop_back();
    }
  }
}
void cycle(long long st, vector<long long int> &ups, vector<long long int> &upe,
           long long cn) {
  for (auto &&it : adj[st]) {
    if (it.first != pa[st] && ups[it.first] > 0) {
      upe.push_back(it.second);
      if (n == 100000 && (long long int)res.size() == 1)
        cout << "In2"
             << "\n";
      for (long long int i = ups[it.first] - 1; i < (long long int)upe.size();
           i++)
        res.push_back(upe[i]);
      fin();
    }
    if (vis[it.first] == 0 && a[it.first] == 0) {
      vis[it.first] = 1;
      upe.push_back(it.second);
      ups[it.first] = cn;
      pa[it.first] = st;
      cycle(it.first, ups, upe, cn + 1);
      ups[it.first] = 0;
      upe.pop_back();
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int TESTS = 1;
  while (TESTS--) {
    cin >> n >> m;
    for (long long int i = 1; i < n + 1; i++) cin >> a[i];
    for (long long int i = 1; i < m + 1; i++) {
      long long u, v;
      cin >> u >> v;
      if (u == v && u == 0 && adj[u].find(v) != adj[u].end()) {
        res.push_back(adj[u][v]);
        res.push_back(i);
        fin();
      }
      adj[u][v] = i;
      adj[v][u] = i;
    }
    for (long long int i = 1; i < n + 1; i++) {
      if (a[i] == -1) mon.push_back(i);
      if (a[i] == 1) on.push_back(i);
    }
    if ((long long int)on.size() + (long long int)mon.size() > 1) {
      for (long long int i = 0; i < (long long int)mon.size(); i++)
        a[mon[i]] = 1;
      long long ind;
      if ((long long int)mon.size() > 0)
        ind = mon[0];
      else
        ind = on[0];
      vis[ind] = 1;
      vector<long long int> upe;
      dfs(ind, upe);
    }
    for (long long int i = 1; i < n + 1; i++)
      if (a[i] == -1) a[i] = 0;
    for (long long int i = 1; i < n + 1; i++) {
      if (vis[i] == 0 && a[i] == 0) {
        pa[i] = -1;
        vis[i] = 1;
        vector<long long int> ups(300005);
        vector<long long int> upe;
        ups[i] = 1;
        cycle(i, ups, upe, 2);
      }
    }
    cout << -1 << "\n";
  }
  return 0;
}
