#include using namespace std; #ifdef LOCAL #include "debug.h" #else #define DEBUG(...) #endif template auto rle(const S& s) { vector res; for (auto c : s) if (empty(res) or res.back().first != c) res.emplace_back(c, 1); else ++res.back().second; return res; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n; cin >> n; vector a(n); for (auto&& e : a) cin >> e; auto v = rle(a); set se; int m = size(v); for (int t = 0; t < m; ++t) { if (se.count(v[t].first)) { if (t == m - 1) { cout << "1\n"; exit(0); } else { cout << "-1\n"; exit(0); } } se.insert(v[t].first); } cout << "0\n"; }