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

import java.util.*;
import java.io.*;

public class LehaGame
{
  static class FastReader
  {
      BufferedReader br;
      StringTokenizer st;

      public FastReader()
      {
          br = new BufferedReader(new
                   InputStreamReader(System.in));
      }

      String next()
      {
          while (st == null || !st.hasMoreElements())
          {
              try
              {
                  st = new StringTokenizer(br.readLine());
              }
              catch (IOException  e)
              {
                  e.printStackTrace();
              }
          }
          return st.nextToken();
      }

      int nextInt()
      {
          return Integer.parseInt(next());
      }

      long nextLong()
      {
          return Long.parseLong(next());
      }

      double nextDouble()
      {
          return Double.parseDouble(next());
      }

      String nextLine()
      {
          String str = "";
          try
          {
              str = br.readLine();
          }
          catch (IOException e)
          {
              e.printStackTrace();
          }
          return str;
      }
  }

  static Edge[] edges;
  static Graph[] graph;
  static char[] color;

  public static void main (String[] args)
  {
    FastReader reader = new FastReader();
    PrintWriter writer = new PrintWriter (System.out);
    int totalNodes = reader.nextInt();
    int totalEdges = reader.nextInt();
    int negatives=0;

    edges = new Edge[totalEdges];
    graph = new Graph[totalNodes];
    color = new char[totalNodes];
    int last = -1;

    for (int i=0; i<totalNodes; i++)
    {
      graph[i] = new Graph();
      color[i] = 'w';
      graph[i].number = reader.nextInt();

      if (graph[i].number == -1)
      {
        negatives++;
        last = i;
      }
    }
    for (int i=0; i<totalEdges; i++)
    {
      edges[i] = new Edge();
      edges[i].u = reader.nextInt()-1;
      edges[i].v = reader.nextInt()-1;

      graph[edges[i].u].list.add (i);
      graph[edges[i].v].list.add (i);
    }

    int faulty=0;
    for (int i=0; i<totalNodes; i++)
    {
      if (graph[i].list.size()%2 != graph[i].number && graph[i].number != -1)
        faulty ^= 1;
    }

    if (faulty == 1 && negatives == 0)
    {
      writer.println (-1);
      writer.close();
      return;
    }

    makeSpanning (0, -1);

    for (int i=0; i<totalNodes; i++)
    {
      if (graph[i].number != -1)
      {
        int correct = 0;
        for (int j=0; j<graph[i].list.size(); j++)
        {
          int e = graph[i].list.get(j);
          if (!edges[e].delete)
            correct++;
        }

        if (correct%2 != graph[i].number)
          graph[i].contention = true;
      }
    }

    if (faulty == 1)
      graph[last].contention = true;

    /*for (int i=0; i<totalEdges; i++)
      System.out.println ((i+1) + " " + edges[i].delete);*/

    trim (0, -1);

    int changes=0;
    for (int i=0; i<totalEdges; i++)
    {
      if (!edges[i].delete)
        changes++;
    }

    writer.println (changes);
    for (int i=0; i<totalEdges; i++)
    {
      if (!edges[i].delete)
        writer.println ((i+1));
    }

    writer.close();
  }

  static void makeSpanning (int node, int parent)
  {
    color[node] = 'g';
    //System.out.println (node + " " + parent + " dfdg");

    for (int i=0; i<graph[node].list.size(); i++)
    {
      int e = graph[node].list.get(i);

      int child = node ^ edges[e].u ^ edges[e].v;

      //System.out.println (child + " " + node + " " + parent + " grett");
      if (child != parent)
      {
        if (color[child] == 'w')
          makeSpanning (child, node);
        else if (color[child] == 'g')
          edges[e].delete = true;
      }
    }

    color[node] = 'b';
  }

  static void trim (int node, int parent)
  {
    int count = 0;
    for (int i=0; i<graph[node].list.size(); i++)
    {
      int e = graph[node].list.get(i);

      int child = node ^ edges[e].u ^ edges[e].v;
      if (child != parent && !edges[e].delete)
      {
        trim (child, node);
        if (graph[child].contention)
        {
          count ^= 1;
          edges[e].delete = true;
        }
      }
    }

    if (count == 1)
      graph[node].contention ^= true;
  }
}

class Graph
{
  int number;
  boolean contention = false;
  ArrayList<Integer> list = new ArrayList<Integer>();
}

class Edge
{
  int u, v;
  boolean delete = false;
}
