#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'

using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = LLONG_MAX/10;
const ll MOD = 1e9+7;


int main(){
  int N;cin>>N;
  vint a(N);
  int xa=0;
  repeat(i,N){
    cin>>a[i];
    xa ^= a[i];
    a[i] ^= a[i]-1;
  }
  debug(xa);
  debugArray(a,N);
  ll ans=0;
  sort(a.begin(),a.end());
  for(int i=31;i>=0;i--){
    if(!((xa>>i)&1))continue;
    int j=lower_bound(a.begin(),a.end(),(1<<i))-a.begin();
    if(a[j]!=(1<<(i+1))-1){
      ans = -1;
      break;
    }
    ans++;
    xa ^= a[j];
  }
  cout << ans << endl;
  return 0;
}
