#include<bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); string s; cin >> s >> s; int n = s.size(); vector<int> cnt(2, 0); for (int i = 0; i < n; ++ i) { cnt[s[i] - '0'] += 1; } if (cnt[0] == 0 or cnt[1] == 0) { cout << "0\n"; } else if (cnt[0] != cnt[1]) { cout << "1\n"; } else if (s == "01" or s == "10") { cout << "-1\n"; } else { cout << "2\n"; } return 0; }