fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. # define ll long long int
  4.  
  5. void solve(){
  6. ll n,y;
  7. cin>>n>>y;
  8. ll arr[n];
  9. ll x=0;
  10. for(ll i=0;i<n;i++){
  11. cin>>arr[i];
  12. x |= arr[i];
  13. }
  14. ll ans = 0;
  15. ans = x^y;
  16. if((ans | x) == y){
  17. cout<<ans<<endl;
  18. return;
  19. }
  20.  
  21. cout<<-1<<endl;
  22. }
  23.  
  24. int main() {
  25.  
  26. ll t;
  27. cin>>t;
  28. while(t--){
  29. solve();
  30. }
  31. return 0;
  32. }
  33.  
Success #stdin #stdout 0.01s 5280KB
stdin
4
4 15
3 5 6 2
3 8
1 2 1
1 1
0
5 7
1 2 4 2 1
stdout
8
-1
1
0