#include using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; vector a(n); for (int i = 0; i < n; i++) cin >> a.at(i); vector x(n + 1); for (int i = 1; i < n; i++) { if (a.at(i) != a.at(i - 1)) x.at(a.at(i))++; } int kind = 0; bool flag = true; for (int i = 1; i <= n; i++) { if (x.at(i) > 0) kind++; if (x.at(i) > 1) flag = false; } if (flag) { if (a.front() == a.back() && kind > 0) cout << "1\n"; else cout << "0\n"; } else { cout << "-1\n"; } }