#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<ll,ll> P;
#define pb push_back
#define ft first
#define sd second
#define mp make_pair
#define fr(i,n) for(int i=0;i<n;i++)
#define Fr(i,n) for(int i=0;i++<n;)
#define ifr(i,n) for(int i=n-1;i>=0;i--)
#define iFr(i,n) for(int i=n;i>0;i--)

int main(){
  unsigned int n,a,x=0,ans=0;
  map<int,bool> ib;
  cin>>n;
  fr(i,n){
    cin>>a;
    x^=a;
    ib[a-(a&(a-1))]=1;
  }
  ifr(i,32){
    if(ib[1<<i]&&((x>>i)&1)){
      ans++;
      x^=(1<<(i+1))-1;
    }
  }
  cout<<(x?-1ll:ans)<<endl;
}