#include int h(int a, int b) { int cnt = 0; while (a > 0 || b > 0) { if (a % 2 != b % 2) cnt++; a /= 2; b /= 2; } return cnt; } int main() { int n; scanf("%d", &n); int i, j; int a[1005]; scanf("%d %d", &a[0], &a[n + 1]); for (i = 0; i < n; i++) scanf("%d", &a[i + 1]); n += 2; int dp[1005]; for (i = 0; i < n; i++) dp[i] = -1; dp[0] = 0; int q[1005], l, r; q[0] = 0; l = 0; r = 1; while (l < r) { i = q[l]; l++; for (j = 0; j < n; j++) { if (h(a[i], a[j]) < 2) { if (dp[j]<0 || dp[j]>dp[i] + 1) { dp[j] = dp[i] + 1; q[r] = j; r++; } } } } if (dp[n - 1] < 0) dp[n - 1]++; printf("%d\n", dp[n - 1] - 1); return 0; }