#include using namespace std; using ll = long long; int main(){ ios::sync_with_stdio(false); cin.tie(0); int n, m, n1, n2, u, v; cin >> n >> m; n1 = n / 2, n2 = n - n1; ll S; vector edge1, edge2; vector edge3; vector dp1(1 << n1, 1 << 29), dp2(1 << n2, 1 << 29); for(int i = 0; i < m; i++){ cin >> u >> v; u--, v--; S = (1ll << u) | (1ll << v); if(max(u, v) < n1) edge1.push_back(S); else if(min(u, v) >= n1) edge2.push_back(S >> n1); else edge3.push_back(S); } S = 0; for(int i = 0; i < n; i++){ cin >> v; S |= (ll)(v) << i; } queue nxt; dp1[S & ((1 << n1) - 1)] = dp2[S >> n1] = 0; nxt.push(S & ((1 << n1) - 1)); while(!nxt.empty()){ v = nxt.front(); nxt.pop(); for(auto &&T : edge1){ if(dp1[v] + 1 >= dp1[v ^ T])continue; dp1[v ^ T] = dp1[v] + 1; nxt.push(v ^ T); } } nxt.push(S >> n1); while(!nxt.empty()){ v = nxt.front(); nxt.pop(); for(auto &&T : edge2){ if(dp2[v] + 1 >= dp2[v ^ T])continue; dp2[v ^ T] = dp2[v] + 1; nxt.push(v ^ T); } } int ans = 1 << 29; for(int i = 0; i < (1 << edge3.size()); i++){ S = 0; for(int j = 0; j < edge3.size(); j++){ if(i >> j & 1) S ^= edge3[j]; } ans = min(ans, dp1[S & ((1 << n1) - 1)] + dp2[S >> n1] + __builtin_popcount(i)); } if(ans >> 29) ans = -1; cout << ans << '\n'; }