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 <iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<cmath>//这个sqrt要用
#include<queue>
using namespace std;
typedef long long LL;
vector<int> G[3 * 100000 + 10];
vector<int> index[3 * 100000 + 10];
LL cntv[3 * 100000 + 10];
vector<int> p[3 * 100000 + 10];
int vis[3 * 100000 + 10];

int main()
{
	ios::sync_with_stdio(false);

	int n, m;
	cin >> n >> m;
	vector<int> D;
	for (size_t i = 0; i < n; i++)
	{
		int a;
		cin >> a;
		D.push_back(a);
	}

	for (int i = 0; i < m; i++)
	{
		int u, v;
		cin >> u >> v;
		u--, v--;
		G[u].push_back(v);
		G[v].push_back(u);
		index[u].push_back(i);
		index[v].push_back(i);
	}
	vector<set<int>> v;
	vector<int> init;
	//for (int i = 0; i < n; i++)init.push_back(0);
	for (int i = 0; i < n; i++)init.push_back(i);
	set<int> tot(init.begin(), init.end());
	set<int> s;

	set<int> tot2;
	for (int i = 0; i < n; i++)
	{
		if (D[i] == -1)
		{
			s.insert(i);
			tot.erase(i);
			tot2.insert(i);
			vis[i]=1;
		}
	}
	v.push_back(s);

	while (!tot.empty())
	{
		set<int> s;
		int solution = 0;
		vector<int> cv;
		for (auto a = tot.begin();a!=tot.end();)
		{
			//看这个节点有没有连在之前消去的节点上
			int flag = false;
			for (int i = 0; i < G[*a].size(); i++)
			{
				if (tot2.find(G[*a][i]) != tot2.end())//优化
				{
					flag = true;
					p[*a].push_back(G[*a][i]);
					solution = 1;
					break;
				}
			}
			if (flag)
			{
				s.insert(*a);
				//cv.push_back(*a);
				a = tot.erase(a);
			}
			else {
				a++;
			}
		}
		if (solution == 0)
		{
			cout << -1 << endl;
			return 0;
		}
		v.push_back(s);
		tot2.insert(s.begin(),s.end());
	}

	vector<int >res;
	LL cnt=0;
	//已经层级堆叠了
	for (auto a = v.rbegin(); a != v.rend(); a++)
	{
		for (auto i : *a)
		{
			if (D[i] == -1)break;


			if (cntv[i] % 2 != D[i])
			{
				for (int j = 0; j < G[i].size(); j++)//在之前的位置放index，优化掉这步
				{
					if (G[i][j] == p[i][0])
					{
						cntv[p[i][0]]++;
						cnt++;
						res.push_back(index[i][j]);
						break;
					}
				}
			}
		}
	}

	cout << cnt << endl;
	for (auto a : res)
	{
		cout << a + 1 << " ";
	}
	cout << endl;

	return 0;
}