#include #define MAXN 40 #define MAXM 40 using namespace std; int n, m, ans, A[MAXM][2]; int main() { scanf("%d%d", &n, &m); for (int i = 0; i < m; i++) { scanf("%d%d", &A[i][0], &A[i][1]); A[i][0]--; A[i][1]--; } long long goal = 0; for (int i = 0; i < n; i++) { long long x; scanf("%lld", &x); goal |= x << i; } unordered_map mp; int half = m / 2; for (int i = 0; i < (1 << half); i++) { long long msk = 0; int cnt = 0; for (int j = 0; j < half; j++) if (i >> j & 1) { msk ^= 1LL << A[j][0]; msk ^= 1LL << A[j][1]; cnt++; } if (mp.count(msk) == 0) mp[msk] = cnt; else mp[msk] = min(mp[msk], cnt); } ans = m + 1; for (int i = 0; i < (1 << (m - half)); i++) { long long msk = 0; int cnt = 0; for (int j = 0; j < m - half; j++) if (i >> j & 1) { msk ^= 1LL << A[j + half][0]; msk ^= 1LL << A[j + half][1]; cnt++; } if (mp.count(goal ^ msk)) ans = min(ans, cnt + mp[goal ^ msk]); } if (ans == m + 1) printf("-1\n"); else printf("%d\n", ans); return 0; }