import java.io.*; import java.util.*; import java.util.stream.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int m = sc.nextInt(); long[] front = new long[m / 2]; long[] rear = new long[m - m / 2]; for (int i = 0; i < m / 2; i++) { front[i] = (1L << (sc.nextInt() - 1)) + (1L << (sc.nextInt() - 1)); } for (int i = 0; i < m - m / 2; i++) { rear[i] = (1L << (sc.nextInt() - 1)) + (1L << (sc.nextInt() - 1)); } long base = 0; for (int i = 0; i < n; i++) { if (sc.nextInt() == 1) { base += (1L << i); } } long[] dp1 = new long[1 <<(m / 2)]; HashMap counts1 = new HashMap<>(); counts1.put(base, 0); dp1[0] = base; for (int i = 1; i < (1 << (m / 2)); i++) { for (int j = 0; j < m / 2; j++) { if ((i & (1 << j)) == 0) { continue; } dp1[i] = dp1[i ^ (1 << j)] ^ front[j]; counts1.put(dp1[i], Math.min(counts1.getOrDefault(dp1[i], m), getPop(i))); break; } } int ans = Integer.MAX_VALUE; long[] dp2 = new long[1 <<(m - m / 2)]; for (int i = 0; i < (1 << (m - m / 2)); i++) { for (int j = 0; j < m - m / 2; j++) { if ((i & (1 << j)) == 0) { continue; } dp2[i] = dp2[i ^ (1 << j)] ^ rear[j]; break; } ans = Math.min(ans, counts1.getOrDefault(dp2[i], m + 1) + getPop(i)); } if (ans > m) { System.out.println(-1); } else { System.out.println(ans); } } static int getPop(int x) { int pop = 0; while (x > 0) { pop += x % 2; x >>= 1; } return pop; } } class Utilities { static String arrayToLineString(Object[] arr) { return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n")); } static String arrayToLineString(int[] arr) { return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new)); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public int[] nextIntArray() throws Exception { return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }