#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<ll,ll> P;
#define pb push_back
#define ft first
#define sd second
#define mp make_pair
#define fr(i,n) for(int i=0;i<n;i++)
#define Fr(i,n) for(int i=0;i++<n;)
#define ifr(i,n) for(int i=n-1;i>=0;i--)
#define iFr(i,n) for(int i=n;i>0;i--)
ll n,d,e[13]={},c;

int f(ll c){
  ll ans=24,cnt=1;
  fr(i,23){
    if((c>>i)&1){
      ans=min(ans,cnt);
      cnt=1;
    }
    else cnt++;
  }
  return min(ans,cnt);
}

int rec(int i,ll c){
  //cout<<i<<" "<<(bitset<23>(c))<<endl;
  if(i==12){
    if(e[12]) return f(c+(1<<11));
    else return f(c);
  }
  if(e[i]==1) return max(rec(i+1,c+(1<<(i-1))),rec(i+1,c+(1<<(23-i))));
  if(e[i]==2) return rec(i+1,c+(1<<(i-1))+(1<<(23-i)));
  return rec(i+1,c);
}

int main(){
  cin>>n;
  fr(i,n){
    cin>>d;
    if(d==0){cout<<0<<endl;return 0;}
    if(++e[d]>2){cout<<0<<endl;return 0;}
    if(d==12&&e[d]>1){cout<<0<<endl;return 0;}
  }
  cout<<rec(1,0)<<endl;
}