#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
	int N;
	cin >> N;
	vector<bool> memo(32, false), memo2(32, false);
	for(int i = 0; i < N; i++){
		int A;
		cin >> A;
		bool flag = false;
		for(int j = 0; j < 32; j++){
			if(A & (1 << j)){
				if(!flag){
					flag = true;
					memo2[j] = true;
				}
				memo[j] = !memo[j];
			}
		}
	}
	int res = 0;
	for(int i = 31; i >= 0; i--){
		if(memo[i]){
			if(!memo2[i]){
				cout << -1 << endl;
				return 0;
			}
			res++;
			for(int j = i; j >= 0; j--){
				memo[j] = !memo[j];
			}
		}
	}
	cout << res << endl;
	return 0;
}