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

from collections import deque

def subtree_specs(graph, d, node, visited, edges_dict, res_edges):
    num_ones = 0
    for nb in graph[node]:
        if not visited[nb]:
            visited[nb] = True
            res = subtree_specs(graph, d, nb, visited, edges_dict, res_edges)
            if res % 2 == 1:
                # Need to attach this node
                res_edges.append(edges_dict[node][nb])
            num_ones += res
    if d[node] == 1:
        num_ones += 1
    return num_ones

def subtree_specs_stack(graph, d, edges_dict):
    n = len(graph)
    visited = n * [False]
    visited[0] = True
    children = [[] for _ in range(n)]
    num_ones = n * [-1]
    res_edges = []
    q = deque([(0, 'InProcess')])
    while len(q) > 0:
        node, state = q.pop()
        if state == 'InProcess':
            for nb in graph[node]:
                if not visited[nb]:
                    visited[nb] = True
                    q.append((nb, 'InProcess'))
                    children[node].append(nb)
            q.append((node, 'Done'))
        elif state == 'Done':
            res = sum([num_ones[i] for i in children[node]])
            if d[node] == 1:
                res += 1
            num_ones[node] = res
            for child in children[node]:
                if num_ones[child] % 2 == 1:
                    res_edges.append(edges_dict[node][child])
    return res_edges

def main():
    n, m = map(int, raw_input().split(' '))
    d = map(int, raw_input().split(' '))
    graph = [[] for _ in range(n)]
    edges_dict = {}

    for i in range(m):
        node1, node2 = map(int, raw_input().split(' '))
        node1 -= 1
        node2 -= 1
        graph[node1].append(node2)
        graph[node2].append(node1)
        if node1 not in edges_dict:
            edges_dict[node1] = {}
        if node2 not in edges_dict:
            edges_dict[node2] = {}
        if node2 not in edges_dict[node1]:
            edges_dict[node1][node2] = i + 1
        if node1 not in edges_dict[node2]:
            edges_dict[node2][node1] = i + 1

    if len([el for el in d if el == 1]) == 0:
        print 0
        return
    else:
        if len([el for el in d if el == 1]) % 2 == 1:
            if len([el for el in d if el == -1]) % 2 == 0:
                print -1
                return
            else:
                i = [i for i in range(len(d)) if d[i] == -1][0]
                d[i] = 1
        res = subtree_specs_stack(graph, d, edges_dict)
        print len(res)
        for el in res:
            print el

if __name__ == "__main__":
    main()
