from collections import defaultdict def popcount(n): c=(n&0x5555555555555555)+((n>>1)&0x5555555555555555) c=(c&0x3333333333333333)+((c>>2)&0x3333333333333333) c=(c&0x0f0f0f0f0f0f0f0f)+((c>>4)&0x0f0f0f0f0f0f0f0f) c=(c&0x00ff00ff00ff00ff)+((c>>8)&0x00ff00ff00ff00ff) c=(c&0x0000ffff0000ffff)+((c>>16)&0x0000ffff0000ffff) c=(c&0x00000000ffffffff)+((c>>32)&0x00000000ffffffff) return c n, m = map(int,input().split()) a = [0] * m b = [0] * m for i in range(m): a[i], b[i] = map(int,input().split()) a[i] -= 1 b[i] -= 1 c = list(map(int,input().split())) v = 0 for i in range(n): v ^= c[i] << i r = defaultdict(lambda: 10 ** 9) r[v] = 0 for i in range(m): for w, c in list(r.items()): x = w ^ (1 << a[i]) ^ (1 << b[i]) if popcount(w) < popcount(x): continue if r[x] > c + 1: r[x] = c + 1 if r[0] == 10 ** 9: print(-1) else: print(r[0])