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

//package codeforces;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class Main {

	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 int cnt;

	private static int min(int a, int b, int c) {
		if (a <= b && a <= c) {
			return a;
		} else if (b <= a && b <= c) {
			return b;
		} else
			return c;
	}

	public static void main(String[] args) {

		FastReader fr = new FastReader();
		int n = fr.nextInt();
		int k = fr.nextInt();
		boolean flag = false;
		ArrayList<Integer>[] group = new ArrayList[n + 1];
		int a[] =new int[n+1];
		for (int i = 0; i < n + 1; i++) {
			group[i] = new ArrayList<Integer>();
		}
		for(int i=1;i<=n;i++){
			a[i] = fr.nextInt();
			if(a[i] == -1){
				flag = true;
			}
		}
		for (int i = 0; i < k; i++) {
			int u = fr.nextInt();
			int v = fr.nextInt();
			/*
			 * if(v<u){ int temp = u; u=v; v=temp; }
			 */
			group[u].add(v);
			group[v].add(u);
		}
		if(flag){
			System.out.println("0");
			return;
		}
		for(int i=1;i<=n;i++){
			if(group[i].size()%2 == a[i]){
				System.out.println("1\n1");
				return;
			}
		}
		System.out.println("-1");
		/*boolean visited[] = new boolean[n + 1];
		visited[1] = true;
		System.out.printf("%.15f", explore(1, group, visited));*/
		// System.out.printf("%.15f",(float)sum/cnt);
	}

	public static float explore(int i, ArrayList<Integer>[] group,
			boolean[] visited) {
		float sum = 0;
		int cnt = 0;
		boolean s = false;
		for (int ii = 0; ii < group[i].size(); ii++) {
			if (!visited[group[i].get(ii)]) {
				cnt++;
			}
		}
		//System.out.println("Group is "+Arrays.toString(visited));
		if (group[i].size() > 0) {
			for (int ii = 0; ii < group[i].size(); ii++) {
				if (!visited[group[i].get(ii)]) {
					s = true;
					visited[group[i].get(ii)] = true;
					sum += 1+ explore(group[i].get(ii), group, visited);
				}
			}
		}
		//System.out.println("i is "+i);
		visited[i] = false;
		if (!s) {
			return 0;
		}
		return (float) sum / cnt;
	}
}