// Arup Guha
// 3/30/2014
// Solution to 2014 Chicago Invitational (NAIPC) Problem C: Diplomacy

/* Note: I got this idea from Nadeem and am not sure of its proof. But, as it can be seen, the implementation is very easy.
 *       the key is an optimal answer can be achieved by just toggling one person back and forth. I suspect an inductive
 *       proof may work to show this.
*/

import java.util.*;

public class c {

	// Stores our graph and original colors.
	public static ArrayList[] graph;
	public static int[] origColors;
	public static int n;
	public static int e;

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);
		n = stdin.nextInt();
		e = stdin.nextInt();

		// Go through each case.
		while (n != 0) {

			// Read in original parties.
			origColors = new int[n];
			graph = new ArrayList[n];
			for (int i=0; i<n; i++) {
				origColors[i] = stdin.nextInt();
				graph[i] = new ArrayList<Integer>();
			}

			// Read in graph.
			for (int i=0; i<e; i++) {
				int v1 = stdin.nextInt() - 1;
				int v2 = stdin.nextInt() - 1;
				graph[v1].add(v2);
				graph[v2].add(v1);
			}

			// Try each person as the person who's mind we switch.
			int best = n;
			for (int i=0; i<n; i++)
				best = Math.min(best, turncoat(i));

			// Here is our answer.
			System.out.println(best);

			// Read in the next case.
			n = stdin.nextInt();
			e = stdin.nextInt();
		}
	}

	// Keep on bugging person k.
	public static int turncoat(int person) {

		int[] mycolors = Arrays.copyOf(origColors, n);

		// Keep on changing person's mind and see how long it takes.
		int cnt = 0;
		while (!equal(mycolors)) {
			boolean[] used = new boolean[n];
			dfs(mycolors, used, person);
			cnt++;
		}

		return cnt;
	}

	// Run a dfs on person on the main graph.
	public static void dfs(int[] colors, boolean[] used, int person) {

		int oldcolor = colors[person];
		colors[person] = 1 - colors[person];
		used[person] = true;

		for (int i=0; i<graph[person].size(); i++)
			if (colors[(Integer)graph[person].get(i)] == oldcolor)
				dfs(colors, used, (Integer)graph[person].get(i));
	}

	// Returns true iff all values in array are the same.
	public static boolean equal(int[] array) {
		for (int i=1; i<array.length; i++)
			if (array[0] != array[i])
				return false;
		return true;
	}
}