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(); ArrayList valueA = new ArrayList<>(); ArrayList valueB = new ArrayList<>(); for (int i = 0; i < m; i++) { long v = (1L << (sc.nextInt() - 1)) + (1L << (sc.nextInt() - 1)); if (i % 2 == 0) { valueA.add(v); } else { valueB.add(v); } } long ans = 0; for (int i = 0; i < n; i++) { ans += (sc.nextLong() << i); } int sizeA = valueA.size(); long[] dpA = new long[1 << sizeA]; dpA[0] = ans; HashMap countsA = new HashMap<>(); countsA.put(ans, 0); for (int i = 0; i < (1 << sizeA); i++) { int pop = getPop(i); for (int j = 0; j < sizeA; j++) { if ((i & (1 << j)) > 0) { dpA[i] = dpA[i ^ (1 << j)] ^ valueA.get(j); break; } } if (!countsA.containsKey(dpA[i]) || countsA.get(dpA[i]) > pop) { countsA.put(dpA[i], pop); } } int sizeB = valueB.size(); long[] dpB = new long[1 << sizeB]; HashMap countsB = new HashMap<>(); countsB.put(0L, 0); for (int i = 0; i < (1 << sizeB); i++) { int pop = getPop(i); for (int j = 0; j < sizeB; j++) { if ((i & (1 << j)) > 0) { dpB[i] = dpB[i ^ (1 << j)] ^ valueB.get(j); break; } } if (!countsB.containsKey(dpB[i]) || countsB.get(dpB[i]) > pop) { countsB.put(dpB[i], pop); } } int result = Integer.MAX_VALUE; for (long x : countsA.keySet()) { if (countsB.containsKey(x)) { result = Math.min(result, countsA.get(x) + countsB.get(x)); } } if (result > n) { System.out.println(-1); } else { System.out.println(result); } } 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(); } }