// #pragma GCC target("avx2") #pragma GCC optimize("O3") // #pragma GCC optimize("unroll-loops") #include using namespace std; using P = pair; const int M = 998244353; const long long LM = 1LL << 60; int main() { cin.tie(0); ios::sync_with_stdio(0); int n, m; cin >> n >> m; vector

edges(m); for (int i = 0; i < m; ++i) { int u, v; cin >> u >> v; --u; --v; edges[i] = { u, v }; } vector c(n); long long st = 0; for (int i = 0; i < n; ++i) { cin >> c[i]; if (c[i] == 1) { st ^= 1LL << i; } } int n1 = m / 2; int n2 = m - n1; unordered_map mp; for (int i = 0; i < (1 << n1); ++i) { long long p = 0; int c = 0; for (int j = 0; j < n1; ++j) { if ((i >> j) & 1) { p ^= (1LL << edges[j].first) ^ (1LL << edges[j].second); ++c; } } if (!mp.count(p)) { mp[p] = c; } mp[p] = min(mp[p], c); } int ans = M; for (int i = 0; i < (1 << n2); ++i) { long long p = 0; int c = 0; for (int j = 0; j < n2; ++j) { if ((i >> j) & 1) { p ^= (1LL << edges[n1 + j].first) ^ (1LL << edges[n1 + j].second); ++c; } } if (mp.count(p ^ st)) { ans = min(ans, mp[p ^ st] + c); } } cout << (ans == M ? -1 : ans) << '\n'; return 0; }