#include using namespace std; int main() { int N; cin >> N; vector T( N ); for( int i = 0; i < N; i++ ) { cin >> T[i]; } int a[7] = { 0, 2, 4, 5, 7, 9, 11 }; vector> d( N ); for( int i = 0; i < N; i++ ) { for( int j = 0; j < 7; j++ ) { for( int dd = 0; dd < 12; dd++ ) { if( (dd + a[j]) % 12 == T[i] ) d[i].push_back( dd ); } } } int ans = -1; for( int j = 0; j < d[0].size(); j++ ) { int dd = d[0][j]; int flag = 0; for( int k = 1; k < N; k++ ) { if( find( d[k].begin(), d[k].end(), dd ) == d[k].end() ) { flag = 1; break; } } if( flag == 0 ) { if( ans < 0 ) ans = dd; else { ans = -1; break; } } } cout << ans << endl; }