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

int main() {
	int N;
	cin >> N;
	vector<int> d(13, 0), single;
	++d[0];
	for(int i=0; i<N; ++i){
	    int a;
	    cin >> a;
	    ++d[a];
	}
	int ans=12;
	for(int i=0; i<=12; ++i){
	    if(d[i]>2) ans=0;
	    if(d[i]==0) continue;
	    if(d[i]==1) single.push_back(i);
	    for(int j=0; j<=12; ++j){
	        if(i==j){
	            if(d[i]==2) ans=min(ans, min(i*2, 24-i*2));
	        }
	        else if(d[j]==0) continue;
	        else if(d[i]==2 || d[j]==2) ans=min(ans, abs(i-j));
	        else ans=min(ans, min(i+j, 24-i-j));
	    }
	}
	for(int i=0; i+2<single.size(); ++i) ans=min(ans, single[i+2]-single[i]);
	cout << ans << endl;
	return 0;
}
