#include using namespace std; using ll=long long; #define rep2(i, a, n) for(int i = (a); i < (n); i++) #define rep(i, n) rep2(i,0,n) int main(){ cin.tie(nullptr);ios_base::sync_with_stdio(false); int n;cin>>n; int hoge[n];rep(i,n)cin>>hoge[i]; int shake=-1,d[7]={0,2,4,5,7,9,11},cnt; rep(i,12){ cnt=0; rep(j,n){ rep(k,7){ if(hoge[j]==(i+d[k])%12)cnt++; } } if(cnt==n&&shake==-1){ shake=i; }else if(cnt==n&&shake!=-1){ shake=-1; break; } } cout<<(shake!=-1?shake:-1)<