N,M = map(int,input().split()) edge = [] for _ in range(M): a,b = map(int,input().split()) a -= 1 b -= 1 edge.append((1 << a) | (1 << b)) c = list(map(int,input().split())) C = 0 for i in range(N): if c[i] == 1: C |= 1 << i import sys D = M // 2 E = M - D d = dict() for bit in range(1 << D): count = 0 tmp = 0 for i in range(D): if bit >> i & 1: count += 1 tmp ^= edge[i] if tmp in d: d[tmp] = min(d[tmp],count) else: d[tmp] = count ans = 50 for bit in range(1 << E): count = 0 tmp = 0 for i in range(E): if bit >> i & 1: count += 1 tmp ^= edge[D + i] if tmp ^ C in d: ans = min(ans,count + d[tmp ^ C]) if ans == 50: print(-1) else: print(ans)