#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(x) (int) x.size()
#define cat(x) cerr << #x << " = " << x << endl
#define all(x) x.begin(), x.end()
#define rep(i, j, n) for (int i = j; i <= n; ++i)
#define per(i, j, n) for (int i = n; j <= i; --i)
 
using ll = long long;
using ld = long double;
using namespace std;

int n, a, x, cnt[30];

int main() {
	scanf ("%d", &n);
	rep(i, 1, n) {
		scanf ("%d", &a);
		x ^= a;
		cnt[__builtin_ctz(a)]++;
	}
	int ans = 0;
	per(i, 0, 29) {
		if (!((x >> i) & 1)) continue;
		if (!cnt[i]) return !printf ("-1\n");
		x ^= (1 << (i + 1)) - 1;
		ans++;
	}
	printf ("%d\n", ans); 
		
	return 0;
}
