#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS  = 1e-10;
const bool debug = 1;
//----------------------//

int N;
int a[112345];

int main() {
	cin >> N;
	REP(i, N) scanf("%d", a + i);
	
	int x = 0;
	REP(i, N) x ^= a[i];
	
	int cnt[32] = {};
	REP(i, N) {
		FOR(j, 1, 32) {
			if ((a[i] >> j & 1) && (a[i] & ((1ll<<j)-1)) == 0) cnt[j]++;
		}
		if (a[i] & 1) cnt[0]++;
	}
	
	int ans = 0;
	for (int i = 31; i >= 0; i--) if (x >> i & 1) {
		if (cnt[i] == 0) { ans = -1; break; }
		x ^= (1ll<<(i+1))-1;
		ans++;;
	}
	
	cout << ans << endl;
	
	return 0;
}
