def popcnt(n): return bin(n).count("1") n,m = map(int,input().split()) a = [] b = [] for _ in range(m): ai, bi = map(int,input().split()) a.append(ai-1) b.append(bi-1) cv = list(map(int,input().split())) c = 0 for i in range(n): if cv[i]: c += (1 << i) seen = set() val = dict() m1 = m // 2 m2 = m - m1 for bt in range((1 << m1)): l = 0 for i in range(m1): if (bt >> i) & 1: l ^= (1 << a[i]) l ^= (1 << b[i]) if l in seen: val[l] = min(val[l], popcnt(bt)) else: val[l] = popcnt(l) seen.add(l) ans = 100000000 for bt in range(1 << m2): l = c for i in range(m2): if (bt >> i) & 1: l ^= (1 << a[m1+i]) l ^= (1 << b[m1+i]) if l in seen: ans = min(ans, val[l] + popcnt(bt)) if ans == 100000000: print(-1) else: print(ans)