#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>


using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define INF64 1999999999999999999
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007


ll n, d = 0, ans = 0;
bool bo[40], tr = true;
int main() {
	cin >> n;
	REP(i, n) {
		ll a;
		cin >> a;
		d ^= a;
		REP(i, 40) {
			if (a & (1ll << i)) {
				bo[i] = true;
				break;
			}
		}
	}
	REPR(i, 37) {
		if ((!(d & (1ll << i)) and (d & (1ll << (i + 1)))) or ((d & (1ll << i)) and !(d & (1ll << (i + 1))))) {

			if (bo[i])ans++;
			else tr = false;
		}
	}
	cout << (tr ? ans : -1) << endl;
}

