#include<iostream>
#include<vector>
#include<map>
using namespace std;

const int INF = 1e9;
const int MAX_N = 50;
const int MAX_BIT = (1 << 24);

int calcDiff(int t, int bit){
  int ret = t;
  for(int i = 0 ; i < 24 ; i++){
    if((bit >> i)&1){
      int time = i;
      ret = min(ret, abs(time - t));
    }
  }
  return ret;
}

int main(){
  int N;
  static int dp[MAX_N+1][MAX_BIT];
  cin >> N;
  vector<int>vec;
  for(int i = 0 ; i < N ; i++){
    int tmp;
    cin >> tmp;
    vec.push_back(tmp);
  }
  for(int i = 0 ; i < MAX_N+1 ; i++){
    for(int j = 0 ; j < MAX_BIT ; j++){
      dp[i][j] = -1;
    }
  }
  dp[0][0] = INF;
  int res = -1;
  for(int i = 0 ; i < N ; i++){
    for(int j = 0 ; j < MAX_BIT ; j++){
      if(dp[i][j] == -1)continue;
      vector<int>cand;
      cand.push_back(vec[i]);
      cand.push_back((24 - vec[i])%24);
      for(int k = 0 ; k < cand.size() ; k++){
        //cout << "i = " << i << endl;
        //cout << "cand[k] = " << cand[k] << endl;
        int min_time = min(calcDiff(cand[k], j), dp[i][j]);
        int next_bit = (j | (1 << cand[k]));
        //cout << "min_time = " << min_time << " next_bit = " << next_bit << endl;
        dp[i+1][next_bit] = max(dp[i+1][next_bit], min_time);
        if(i+1 == N){
          res = max(res, dp[i+1][next_bit]);
        }
      }
    }
  }
  cout << res << endl;
  return 0;
}
