#include using namespace std; using ll = long long; #define rep(i, s, e) for (int i = (int)(s); i < (int)(e); ++i) #define all(a) (a).begin(),(a).end() int hamDist(ll a, ll b) { int res = 0; while (a > 0 || b > 0) { if ((a & 1) ^ (b & 1)) ++res; a >>= 1; b >>= 1; } return res; } int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); int N; cin >> N; vector S(N + 2); cin >> S[0] >> S[N + 1]; rep(i, 1, N + 1) cin >> S[i]; vector dist(N + 2, -1); queue que; dist[0] = 0; que.push(0); while (!que.empty()) { int v = que.front(); que.pop(); rep(next, 1, N + 2) { if (dist[next] != -1 || v == next) continue; if (hamDist(S[v], S[next]) <= 1) { dist[next] = dist[v] + 1; que.push(next); } } } if (dist[N + 1] == -1) cout << -1 << '\n'; else cout << dist[N + 1] - 1 << '\n'; }